Skip to content

Commit 98af79b

Browse files
authored
Merge pull request #1326 from microsoft/fix/scope-completions
fix: completions not returning stack variables
2 parents 48125df + f10c0e1 commit 98af79b

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he
55
## Nightly (only)
66

77
- fix: performance improvements for setting breakpoints in large projects ([vscode#153470](https://github.com/microsoft/vscode/issues/153470))
8+
- fix: completions not returning stack variables ([vscode#153651](https://github.com/microsoft/vscode/issues/153651))
89

910
## v1.69 (June 2022)
1011

src/adapter/completions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,18 @@ export class Completions {
376376
isInGlobalScope: true,
377377
});
378378

379-
if (!items.length) {
380-
continue;
381-
}
382-
383379
if (options.stackFrame) {
384380
// When evaluating on a call frame, also autocomplete with scope variables.
381+
const lowerPrefix = prefix.toLowerCase();
385382
const names = new Set(items.map(item => item.label));
386383
for (const completion of await options.stackFrame.completions()) {
387-
if (names.has(completion.label)) continue;
384+
if (
385+
names.has(completion.label) ||
386+
!completion.label.toLowerCase().includes(lowerPrefix)
387+
) {
388+
continue;
389+
}
390+
388391
names.add(completion.label);
389392
items.push(completion as ICompletionWithSort);
390393
}

src/test/completion/completion.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,41 @@ describe('completion', () => {
196196
}
197197
});
198198

199+
itIntegrates('completes in scope (vscode#153651)', async ({ r }) => {
200+
const p = await r.launch(`
201+
<script>
202+
function foo() {
203+
const helloWorld = '';
204+
debugger;
205+
}
206+
207+
foo();
208+
</script>
209+
`);
210+
211+
const untilStopped = p.dap.once('stopped');
212+
p.load();
213+
214+
const frame = (
215+
await p.dap.stackTrace({
216+
threadId: (await untilStopped).threadId!,
217+
})
218+
).stackFrames[0];
219+
220+
const actual = await p.dap.completions({
221+
text: 'helloW',
222+
column: 7,
223+
frameId: frame.id,
224+
});
225+
226+
expect(actual.targets).to.deep.equal([
227+
{
228+
label: 'helloWorld',
229+
type: 'property',
230+
},
231+
]);
232+
});
233+
199234
itIntegrates('$returnValue', async ({ r }) => {
200235
const getFrameId = async () =>
201236
(

0 commit comments

Comments
 (0)