@@ -153,7 +153,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
153153 label : grammar . scopeName || `source.${ grammar . language } ` ,
154154 description : grammar . language ,
155155 } ,
156- documentation : documentPath ,
156+ documentation : relativePath ,
157157 range : cursorRange ,
158158 kind : vscode . CompletionItemKind . Variable ,
159159 } ) ;
@@ -426,18 +426,20 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
426426 }
427427 const candidateScopePostfix = '.' + candidatePostfixes . candidatePostfixes [ 0 ] ;
428428
429- const mergedScopePostfix = mergeCandidatesScopePostfix ( candidatePostfixes . cursorScope , candidatePostfixes . candidatePostfixes , true ) ;
430- if ( mergedScopePostfix . candidatePostfix !== undefined ) {
431- completionItems . push ( {
432- label : {
433- label : candidatePostfixes . cursorScope ,
434- detail : mergedScopePostfix . scopePostfixEnding ,
435- } ,
436- range : cursorRange ,
437- kind : vscode . CompletionItemKind . Text ,
438- sortText : ` ${ candidatePostfixes . cursorScope } ` ,
439- insertText : candidatePostfixes . cursorScope + mergedScopePostfix . scopePostfixEnding ,
440- } ) ;
429+ if ( candidatePostfixes . cursorScope ) {
430+ const mergedScopePostfix = mergeCandidatesScopePostfix ( candidatePostfixes . cursorScope , candidatePostfixes . candidatePostfixes , true ) ;
431+ if ( mergedScopePostfix . candidatePostfix !== undefined ) {
432+ completionItems . push ( {
433+ label : {
434+ label : candidatePostfixes . cursorScope ,
435+ detail : mergedScopePostfix . candidatePostfixEnding ,
436+ } ,
437+ range : cursorRange ,
438+ kind : vscode . CompletionItemKind . Text ,
439+ sortText : ` ${ candidatePostfixes . cursorScope } ` ,
440+ insertText : candidatePostfixes . cursorScope + mergedScopePostfix . candidatePostfixEnding ,
441+ } ) ;
442+ }
441443 }
442444
443445 for ( const scope in themeScopes ) {
@@ -864,7 +866,7 @@ export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node): {
864866 candidatePostfixes : string [ ] ;
865867} ;
866868export function findCandidateScopePostfixes ( rootNode : webTreeSitter . Node , position : vscode . Position ) : {
867- cursorScope : string ;
869+ cursorScope : string | undefined ;
868870 scopes : { [ scope : string ] : number ; } ;
869871 scopeCaptures : webTreeSitter . QueryCapture [ ] ;
870872 candidatePostfixes : string [ ] ;
@@ -886,6 +888,7 @@ export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node, positi
886888 (contentName (value (scope) @scope (.not-match? @scope "^(\\\\$0*[0-9]{1,3})+$")))
887889 (name_scopeName (value (scope) @scope (.not-match? @scope "^(\\\\$0*[0-9]{1,3})+$")))
888890 (injectionSelector (value (scope) @injectionScope (.not-match? @injectionScope "^(\\\\$0*[0-9]{1,3})+$")))
891+ (injections (injection (key (scope) @injectionScope (.not-match? @injectionScope "^(\\\\$0*[0-9]{1,3})+$"))))
889892 (include (value (scopeName) @includeScope (.not-match? @includeScope "^(\\\\$0*[0-9]{1,3})+$")))
890893 ` ;
891894 const scopeCaptures = queryNode ( rootNode , scopeQuery ) ;
@@ -962,7 +965,7 @@ export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node, positi
962965 } ;
963966}
964967
965- export function mergeCandidatesScopePostfix ( scope : string , candidates : readonly string [ ] , merge ?: boolean ) {
968+ export function mergeCandidatesScopePostfix ( scope : string , candidates : readonly string [ ] , forceMerge ?: boolean ) {
966969 const subScopes : string [ ] = [ ] ;
967970 const scopeParts = scope . split ( '.' ) ;
968971
@@ -976,33 +979,41 @@ export function mergeCandidatesScopePostfix(scope: string, candidates: readonly
976979
977980 const candidatePostfix = candidates [ 0 ] ;
978981 if ( candidatePostfix . startsWith ( subScopePostfix )
979- && ( merge || candidatePostfix . split ( '.' ) [ 0 ] != subScopePostfix ) ) {
982+ && ( forceMerge || candidatePostfix . split ( '.' ) [ 0 ] != subScopePostfix ) ) {
980983 return {
981- scopePostfixEnding : candidatePostfix . slice ( subScopePostfix . length ) ,
982984 subScopePostfix,
983985 candidatePostfix,
986+ candidatePostfixEnding : candidatePostfix . slice ( subScopePostfix . length ) ,
984987 } ;
985988 }
986989 }
987990
988991 // Test for longest postfix
989992 for ( let index = 1 ; index < scopeParts . length ; index ++ ) {
990993 const subScopePostfix = scopeParts . slice ( index ) . join ( '.' ) ;
991- if ( ! subScopePostfix ) {
994+ if ( ! subScopePostfix && ! forceMerge ) {
992995 continue ;
993996 }
994997
995998 for ( const candidatePostfix of candidates ) {
996999 if ( candidatePostfix . startsWith ( subScopePostfix )
997- && ( merge || candidatePostfix /* .split('.')[0] */ != subScopePostfix ) ) {
1000+ && ( forceMerge || candidatePostfix /* .split('.')[0] */ != subScopePostfix ) ) {
9981001 return {
999- scopePostfixEnding : candidatePostfix . slice ( subScopePostfix . length ) ,
10001002 subScopePostfix,
10011003 candidatePostfix,
1004+ candidatePostfixEnding : candidatePostfix . slice ( subScopePostfix . length ) ,
10021005 } ;
10031006 }
10041007 }
10051008 }
10061009
1010+ if ( forceMerge ) {
1011+ return {
1012+ subScopePostfix : scope ,
1013+ candidatePostfix : candidates [ 0 ] ,
1014+ candidatePostfixEnding : '.' + candidates [ 0 ] ,
1015+ } ;
1016+ }
1017+
10071018 return { subScopes } ;
10081019}
0 commit comments