提交 9d2787e4 编写于 作者: M Matt Bierner

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.
上级 7a4944fb
......@@ -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');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册