@@ -6,17 +6,18 @@ import { getScopes } from "../themeScopeColors";
66import { UNICODE_PROPERTIES } from "../UNICODE_PROPERTIES" ;
77import { unicode_property_data } from "../unicode_property_data" ;
88import { SyntaxNode } from 'web-tree-sitter' ;
9- import { getPackageJSON } from '../extension' ;
9+ import { getPackageJSON , sleep } from '../extension' ;
1010
1111type CompletionItem = vscode . CompletionItem & { type ?: string ; } ;
1212
1313const triggerCharacterSets : { [ key : string ] : string [ ] ; } = {
14- schema : [ '"' , ':' ] ,
14+ schema : [ '"' ] ,
15+ schema_new : [ ':' ] ,
1516 scopeName : [ '"' , '.' ] ,
1617 name : [ '"' ] ,
1718 include : [ '"' , '#' , '.' , '$' ] ,
18- new_scope : [ '"' , ' ' ] ,
1919 scope : [ '.' , '$' ] ,
20+ scope_new : [ '"' , ' ' ] ,
2021 regex : [ '{' , '^' , /* '\\', '(', '?', '<', '\'' */ ] ,
2122} ;
2223export const triggerCharacters = Object . values ( triggerCharacterSets ) . flat ( ) ;
@@ -53,6 +54,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
5354 async provideCompletionItems ( document : vscode . TextDocument , position : vscode . Position , token : vscode . CancellationToken , context : vscode . CompletionContext ) : Promise < vscode . CompletionList < vscode . CompletionItem > > {
5455 // vscode.window.showInformationMessage(JSON.stringify("Completions"));
5556 // const start = performance.now();
57+ await sleep ( 50 ) ; // partially avoids race condition with reparseTextDocument()
5658
5759 const trees = getTrees ( document ) ;
5860 const tree = trees . jsonTree ;
@@ -61,14 +63,14 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
6163
6264 const cursorQuery = `;scm
6365 (schema (value) @schema)
64- (schema) @new_schema
66+ (schema) @schema_new
6567 (scopeName (value) @scopeName)
6668 (name_display (value) @name)
6769 (include (value) @include)
68- (name (value) @new_scope)
6970 (name (value (scope) @scope))
70- (contentName (value) @new_scope )
71+ (name (value) @scope_new )
7172 (contentName (value (scope) @scope))
73+ (contentName (value) @scope_new)
7274 (regex) @regex
7375 ` ;
7476 const cursorCapture = queryNode ( rootNode , cursorQuery , point ) ;
@@ -82,16 +84,16 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
8284 }
8385 }
8486 const cursorNode = cursorCapture . node ;
85- const cursorRange = toRange ( cursorNode ) ;
87+ const cursorRange = cursorName . endsWith ( "_new" ) ? new vscode . Range ( position , position ) : toRange ( cursorNode ) ;
8688 const completionItems : CompletionItem [ ] = [ ] ;
8789
8890 switch ( cursorName ) {
89- case 'new_schema' :
9091 case 'schema' :
92+ case 'schema_new' :
9193 const schema = "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json" ;
9294 completionItems . push ( {
9395 label : cursorName == 'schema' ? schema : `"${ schema } "` ,
94- range : cursorName == 'schema' ? cursorRange : new vscode . Range ( position , cursorRange . end ) ,
96+ range : cursorRange ,
9597 kind : vscode . CompletionItemKind . Reference ,
9698 documentation : "Schema for VSCode's TextMate JSON grammars" ,
9799 sortText : ' ' ,
@@ -310,7 +312,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
310312 }
311313 break ;
312314 case 'scope' :
313- case 'new_scope ' :
315+ case 'scope_new ' :
314316 const themeScopes = await getScopes ( ) ;
315317 for ( const key in themeScopes ) {
316318 const scope = themeScopes [ key ] ;
@@ -330,7 +332,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
330332 // detail: scope.foreground,
331333 description : scope . name ,
332334 } ,
333- range : cursorName == 'scope' ? cursorRange : null ,
335+ range : cursorRange ,
334336 kind : vscode . CompletionItemKind . Color ,
335337 detail : scope . foreground || scope . background ,
336338 documentation : documentation ,
@@ -362,7 +364,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
362364 label : scope ,
363365 description : "VSCode Debug Tokens" ,
364366 } ,
365- range : cursorName == 'scope' ? cursorRange : null ,
367+ range : cursorRange ,
366368 kind : vscode . CompletionItemKind . Color ,
367369 detail : settings . foreground || settings . background ,
368370 sortText : `~${ scope } ` ,
@@ -388,7 +390,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
388390 }
389391 completionItems . push ( {
390392 label : scope ,
391- range : cursorName == 'scope' ? cursorRange : null ,
393+ range : cursorRange ,
392394 kind : vscode . CompletionItemKind . Text ,
393395 sortText : ` ${ scope } ` ,
394396 } ) ;
0 commit comments