Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix #331 - fix global completions when not at BP
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jun 2, 2018
1 parent 9f96a82 commit 89bcef1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2712,20 +2712,11 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
expression = prefix.substr(0, dot);
}

if (expression) {
logger.verbose(`Completions: Returning for expression '${expression}'`);
const getCompletionsFn = `(function(x){var a=[];for(var o=x;o!==null&&typeof o !== 'undefined';o=o.__proto__){a.push(Object.getOwnPropertyNames(o))};return a})(${expression})`;
const response = await this.waitThenDoEvaluate(getCompletionsFn, args.frameId, { returnByValue: true });
if (response.exceptionDetails) {
return { targets: [] };
} else {
return { targets: this.getFlatAndUniqueCompletionItems(response.result.value) };
}
} else {
if (typeof args.frameId === 'number' && !expression) {
logger.verbose(`Completions: Returning global completions`);

// If no expression was passed, we must be getting global completions at a breakpoint
if (typeof args.frameId !== 'number' || !this._frameHandles.get(args.frameId)) {
if (!this._frameHandles.get(args.frameId)) {
return Promise.reject(errors.stackFrameNotValid());
}

Expand All @@ -2743,6 +2734,17 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
variableArrs.map(variableArr => variableArr.map(variable => variable.name)));
return { targets };
});
} else {
expression = expression || 'this';

logger.verbose(`Completions: Returning for expression '${expression}'`);
const getCompletionsFn = `(function(x){var a=[];for(var o=x;o!==null&&typeof o !== 'undefined';o=o.__proto__){a.push(Object.getOwnPropertyNames(o))};return a})(${expression})`;
const response = await this.waitThenDoEvaluate(getCompletionsFn, args.frameId, { returnByValue: true });
if (response.exceptionDetails) {
return { targets: [] };
} else {
return { targets: this.getFlatAndUniqueCompletionItems(response.result.value) };
}
}
}

Expand Down

0 comments on commit 89bcef1

Please sign in to comment.