Skip to content

Commit 2a4cc5e

Browse files
committed
Improve $schema code completion
1 parent d8a14c9 commit 2a4cc5e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Providers/CompletionItemProvider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as Parser from 'web-tree-sitter';
33
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";
55
import { ITextMateThemingRule } from "../extensions";
66
import { getScopes } from "../themeScopeColors";
77
import { UNICODE_PROPERTIES } from "../UNICODE_PROPERTIES";
@@ -50,6 +50,9 @@ const defaultThemeColors: { [baseTheme: string]: ITextMateThemingRule[]; } = {
5050
]
5151
};
5252

53+
function comma(cursorNode: Node, position: vscode.Position) {
54+
return toPosition(cursorNode.lastNamedChild!.endPosition).isBefore(position) ? '' : ',';
55+
}
5356

5457
export const CompletionItemProvider: vscode.CompletionItemProvider = {
5558
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 = {
9497
case 'schema_new':
9598
const schema = "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json";
9699
completionItems.push({
97-
label: cursorName == 'schema' ? schema : `"${schema}"`,
100+
label: `"${schema}"`,
98101
range: cursorRange,
99102
kind: vscode.CompletionItemKind.Reference,
100103
documentation: "Schema for VSCode's JSON TextMate grammars",
101-
sortText: ' ',
104+
insertText: cursorName == 'schema' ? schema : `"${schema}"${comma(cursorNode, position)}`,
105+
sortText: ' ', // top
102106
});
103107
break;
104108
case 'scopeName':

0 commit comments

Comments
 (0)