Skip to content

Completions fail when the completed name matches a variable in the enumeration template #2399

Description

Problem

Completing properties on a primitive (target., 'abc'., 42.) while paused evaluates enumerateProperties as a string on the call frame using template. Code that will be evaluated is constructed on line 351.

if (!objRefResult.result.objectId) {
const primitiveParams = {
...params,
returnByValue: true,
throwOnSideEffect: false,
expression: enumeratePropertiesTemplate.expr(
`(${expression})`,
JSON.stringify(prefix),
JSON.stringify(isInGlobalScope),
),
};
const propsResult = await this.evaluator.evaluate(
callFrameId
? { ...primitiveParams, callFrameId }
: { ...primitiveParams, contextId: executionContextId },
);
return !propsResult || propsResult.exceptionDetails
? { result: [], isArray: false }
: propsResult.result.value;
}

The template binds the user expression to its own parameters:

(() => {
  let target = (target);
  let prefix = "";
  let isGlobal = false;
  // ... enumerate properties of `target`
})()

If the name being completed is also a parameter or local in that template (target, prefix, isGlobal, or a minified name like n), the inner target refers to the template binding instead of the user variable. Evaluation throws and completions are empty.

This does not affect objects: they are enumerated with Runtime.callFunctionOn on an objectId, so the helper never runs as source in the call frame.

In the currently released version, the following completion won't work because of described error (minified extension sources contain variable named n):

let n = 1
debugger
// n.

Proposed fix

The first evaluate already returned the primitive. Interpolate that value into the template (let target = 1) and run it with Runtime.evaluate (no call frame). The template no longer reads locals, so names cannot clash.

VS Code Version: 1.134.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions