From ccab737399249a8c2230ed6adfec579c7d724364 Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Tue, 7 Mar 2017 16:47:08 +0200 Subject: [PATCH] fix: Make autocompletion in REPL work 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 . * 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". --- lib/internal/inspect_repl.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/inspect_repl.js b/lib/internal/inspect_repl.js index c61bbc9..e246b70 100644 --- a/lib/internal/inspect_repl.js +++ b/lib/internal/inspect_repl.js @@ -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) { @@ -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) {