mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 17:19:01 +01:00
Accepting a member completion should result in valid code
Fixes #58597 Default to replacing the word range in js/ts. This is a change in core behavior so we'll need to see what the feedback is like for it.
This commit is contained in:
@@ -125,11 +125,17 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||
|
||||
// Try getting longer, prefix based range for completions that span words
|
||||
const wordRange = this.document.getWordRangeAtPosition(this.position);
|
||||
if (wordRange) {
|
||||
this.range = wordRange;
|
||||
}
|
||||
|
||||
const text = line.slice(Math.max(0, this.position.character - this.label.length), this.position.character).toLowerCase();
|
||||
const entryName = this.label.toLowerCase();
|
||||
for (let i = entryName.length; i >= 0; --i) {
|
||||
if (text.endsWith(entryName.substr(0, i)) && (!wordRange || wordRange.start.character > this.position.character - i)) {
|
||||
this.range = new vscode.Range(this.position.line, Math.max(0, this.position.character - i), this.position.line, this.position.character);
|
||||
this.range = new vscode.Range(
|
||||
new vscode.Position(this.position.line, Math.max(0, this.position.character - i)),
|
||||
this.position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,20 @@ suite('TypeScript Completions', () => {
|
||||
));
|
||||
});
|
||||
|
||||
test('Accepting a member completion should result in valid code. #58597', async () => {
|
||||
await createTestEditor(testDocumentUri,
|
||||
`const abc = 123;`,
|
||||
`ab$0c`
|
||||
);
|
||||
|
||||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables);
|
||||
assert.strictEqual(
|
||||
document.getText(),
|
||||
joinLines(
|
||||
`const abc = 123;`,
|
||||
`abc`
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
const joinLines = (...args: string[]) => args.join('\n');
|
||||
|
||||
Reference in New Issue
Block a user