Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
repl: make tab completion read up the prototype of "global"
Browse files Browse the repository at this point in the history
For example, there's a global "toString()" function, so the REPL's
tab completion should pick that up.
  • Loading branch information
TooTallNate committed Apr 26, 2012
1 parent 98b4596 commit f405daa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/repl.js
Expand Up @@ -535,6 +535,10 @@ REPLServer.prototype.complete = function(line, callback) {
if (this.useGlobal ||
this.context.constructor &&
this.context.constructor.name === 'Context') {
var contextProto = this.context;
while (contextProto = Object.getPrototypeOf(contextProto)) {
completionGroups.push(Object.getOwnPropertyNames(contextProto));
}
completionGroups.push(Object.getOwnPropertyNames(this.context));
addStandardGlobals();
completionGroupsLoaded();
Expand Down
6 changes: 6 additions & 0 deletions test/simple/test-repl-tab-complete.js
Expand Up @@ -202,3 +202,9 @@ testMe.complete(' ', function(error, data) {
assert.deepEqual(data, [[],undefined]);
clearTimeout(spaceTimeout);
});

// tab completion should pick up the global "toString" object, and
// any other properties up the "global" object's prototype chain
testMe.complete('toSt', function(error, data) {
assert.deepEqual(data, [['toString'], 'toSt']);
});

0 comments on commit f405daa

Please sign in to comment.