|
1 | 1 | import * as vscode from 'vscode'; |
2 | 2 | import * as Parser from 'web-tree-sitter'; |
3 | 3 | import { Node } from 'web-tree-sitter'; |
4 | | -import { getTrees, toRange, toPoint, queryNode, getLastNode, trees } from "../TreeSitter"; |
| 4 | +import { getTrees, toRange, toPoint, queryNode, getLastNode, trees, toPosition } from "../TreeSitter"; |
5 | 5 | import { ITextMateThemingRule } from "../extensions"; |
6 | 6 | import { getScopes } from "../themeScopeColors"; |
7 | 7 | import { UNICODE_PROPERTIES } from "../UNICODE_PROPERTIES"; |
@@ -50,6 +50,9 @@ const defaultThemeColors: { [baseTheme: string]: ITextMateThemingRule[]; } = { |
50 | 50 | ] |
51 | 51 | }; |
52 | 52 |
|
| 53 | +function comma(cursorNode: Node, position: vscode.Position) { |
| 54 | + return toPosition(cursorNode.lastNamedChild!.endPosition).isBefore(position) ? '' : ','; |
| 55 | +} |
53 | 56 |
|
54 | 57 | export const CompletionItemProvider: vscode.CompletionItemProvider = { |
55 | 58 | async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionList<vscode.CompletionItem> | undefined> { |
@@ -94,11 +97,12 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = { |
94 | 97 | case 'schema_new': |
95 | 98 | const schema = "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json"; |
96 | 99 | completionItems.push({ |
97 | | - label: cursorName == 'schema' ? schema : `"${schema}"`, |
| 100 | + label: `"${schema}"`, |
98 | 101 | range: cursorRange, |
99 | 102 | kind: vscode.CompletionItemKind.Reference, |
100 | 103 | documentation: "Schema for VSCode's JSON TextMate grammars", |
101 | | - sortText: ' ', |
| 104 | + insertText: cursorName == 'schema' ? schema : `"${schema}"${comma(cursorNode, position)}`, |
| 105 | + sortText: ' ', // top |
102 | 106 | }); |
103 | 107 | break; |
104 | 108 | case 'scopeName': |
|
0 commit comments