Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
fix: Make autocompletion in REPL work
Browse files Browse the repository at this point in the history
There was a bug in `internal/inspect_repl.js` that caused REPL to crash
when trying to invoke autocomplete. Steps to reproduce:

* Start the debugger.
* Run `repl` command.
* Type any letter.
* Press <Tab>.
* Debugger crashes with `TypeError: elem.indexOf is not a function`.

The reason is that Node's REPL expects a completion group to be an
array of strings while node-inspect passed an instance of ScopeSnapshot.

This commit fixes it by adding completion groups for REPL as properties
of ScopeSnapshot instances and returning them when evaluating ".scope".
  • Loading branch information
aqrln committed Mar 7, 2017
1 parent 37cc9b7 commit ccab737
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class ScopeSnapshot {
const value = new RemoteObject(prop.value);
return [prop.name, value];
}));
this.completionGroup = properties.map((prop) => prop.name);
}

[util.inspect.custom](depth, opts) {
Expand Down Expand Up @@ -480,7 +481,9 @@ function createRepl(inspector) {
if (!selectedFrame) {
return Promise.reject(new Error('Requires execution to be paused'));
}
return selectedFrame.loadScopes();
return selectedFrame.loadScopes().then((scopes) => {
return scopes.map((scope) => scope.completionGroup);
});
}

if (selectedFrame) {
Expand Down

0 comments on commit ccab737

Please sign in to comment.