json: use default word pattern (#151754)

This commit is contained in:
Martin Aeschlimann
2022-06-13 14:36:42 +02:00
committed by GitHub
parent 53130238b4
commit 375681e51e
6 changed files with 150 additions and 86 deletions

View File

@@ -24,7 +24,7 @@ export class PackageDocument {
}
private provideLanguageOverridesCompletionItems(location: Location, position: vscode.Position): vscode.ProviderResult<vscode.CompletionItem[]> {
let range = this.document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
let range = this.getReplaceRange(location, position);
const text = this.document.getText(range);
if (location.path.length === 2) {
@@ -65,6 +65,17 @@ export class PackageDocument {
return Promise.resolve([]);
}
private getReplaceRange(location: Location, position: vscode.Position) {
const node = location.previousNode;
if (node) {
const nodeStart = this.document.positionAt(node.offset), nodeEnd = this.document.positionAt(node.offset + node.length);
if (nodeStart.isBeforeOrEqual(position) && nodeEnd.isAfterOrEqual(position)) {
return new vscode.Range(nodeStart, nodeEnd);
}
}
return new vscode.Range(position, position);
}
private newSimpleCompletionItem(text: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
const item = new vscode.CompletionItem(text);
item.kind = vscode.CompletionItemKind.Value;