Skip to content

Commit 4490d96

Browse files
authored
Merge pull request #2191 from microsoft/connor4312/vscode-243409
fix: explicitly specify completion ranges
2 parents c1b740a + 8c1c328 commit 4490d96

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
This changelog records changes to stable releases since 1.50.2. "TBA" changes here may be available in the [nightly release](https://github.com/microsoft/vscode-js-debug/#nightly-extension) before they're in stable. Note that the minor version (`v1.X.0`) corresponds to the VS Code version js-debug is shipped in, but the patch version (`v1.50.X`) is not meaningful.
44

5-
## 1.99 (March 2025)
5+
## 1.100 (April 2025)
66

7+
- fix: explicitly specify completion ranges ([[vscode#243409](https://github.com/microsoft/vscode/issues/243409)])
78
- fix: memory leak between debug sessions ([#2173](https://github.com/microsoft/vscode-js-debug/issues/2173))
89
- fix: support `npm.scriptRunner: node`
910

src/adapter/completions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export class Completions {
217217
) {
218218
// Walk through the expression and look for any locally-declared variables or identifiers.
219219
const localIdentifiers: ICompletionWithSort[] = [];
220+
const start = getStart(node);
220221
traverse(source, {
221222
enter(node) {
222223
const completion = inferCompletionInfoForDeclaration(node);
@@ -230,7 +231,7 @@ export class Completions {
230231
},
231232
});
232233

233-
const prefix = options.expression.slice(getStart(node), offset);
234+
const prefix = options.expression.slice(start, offset);
234235
const completions = [
235236
...localIdentifiers,
236237
...(await this.defaultCompletions(options, prefix)),
@@ -248,6 +249,11 @@ export class Completions {
248249
});
249250
}
250251

252+
for (const completion of completions) {
253+
completion.start = start;
254+
completion.length = offset - start;
255+
}
256+
251257
return completions;
252258
}
253259

src/test/completion/completion.test.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@ import { itIntegrates } from '../testIntegrationUtils';
88

99
describe('completion', () => {
1010
const tcases: [string, Dap.CompletionItem[]][] = [
11-
['ar|', [{ label: 'arr', sortText: '~~arr', type: 'variable', detail: 'Array' }]],
12-
['ar|.length', [{ label: 'arr', sortText: '~~arr', type: 'variable', detail: 'Array' }]],
11+
['ar|', [{
12+
label: 'arr',
13+
sortText: '~~arr',
14+
type: 'variable',
15+
detail: 'Array',
16+
start: 0,
17+
length: 2,
18+
}]],
19+
['ar|.length', [{
20+
label: 'arr',
21+
sortText: '~~arr',
22+
type: 'variable',
23+
detail: 'Array',
24+
start: 0,
25+
length: 2,
26+
}]],
1327
[
1428
'arr.|',
1529
[
@@ -106,21 +120,51 @@ describe('completion', () => {
106120
},
107121
],
108122
],
109-
['ob|', [{ label: 'obj', sortText: '~~obj', type: 'variable', detail: 'Object' }]],
123+
['ob|', [{
124+
label: 'obj',
125+
sortText: '~~obj',
126+
type: 'variable',
127+
detail: 'Object',
128+
start: 0,
129+
length: 2,
130+
}]],
110131
[
111132
'arr[myStr|',
112-
[{ label: 'myString', sortText: '~~myString', type: 'variable', detail: 'string' }],
133+
[{
134+
label: 'myString',
135+
sortText: '~~myString',
136+
type: 'variable',
137+
detail: 'string',
138+
start: 4,
139+
length: 5,
140+
}],
113141
],
114142
['const replVar = 42; replV|', [{
115143
label: 'replVar',
116144
sortText: 'replVar',
117145
type: 'variable',
146+
start: 20,
147+
length: 5,
118148
}]],
119149
[
120150
'MyCoolCl|',
121-
[{ label: 'MyCoolClass', sortText: '~~MyCoolClass', type: 'class', detail: 'fn()' }],
151+
[{
152+
label: 'MyCoolClass',
153+
sortText: '~~MyCoolClass',
154+
type: 'class',
155+
detail: 'fn()',
156+
start: 0,
157+
length: 8,
158+
}],
122159
],
123-
['Strin|', [{ label: 'String', sortText: '~~String', type: 'class', detail: 'fn(?)' }]],
160+
['Strin|', [{
161+
label: 'String',
162+
sortText: '~~String',
163+
type: 'class',
164+
detail: 'fn(?)',
165+
start: 0,
166+
length: 5,
167+
}]],
124168
[
125169
'myNeatFun|',
126170
[
@@ -129,6 +173,8 @@ describe('completion', () => {
129173
sortText: '~~myNeatFunction',
130174
type: 'function',
131175
detail: 'fn()',
176+
start: 0,
177+
length: 9,
132178
},
133179
],
134180
],
@@ -258,6 +304,8 @@ describe('completion', () => {
258304
{
259305
label: 'helloWorld',
260306
type: 'property',
307+
start: 0,
308+
length: 6,
261309
},
262310
]);
263311
});

0 commit comments

Comments
 (0)