@@ -26,7 +26,7 @@ const triggerCharacterSets: { [key: string]: string[]; } = {
2626} ;
2727export const triggerCharacters = Object . values ( triggerCharacterSets ) . flat ( ) ;
2828
29- const defaultThemeColors : { [ baseTheme : string ] : ITextMateThemingRule [ ] ; } = {
29+ const builtInThemeColors : { [ baseTheme : string ] : ITextMateThemingRule [ ] ; } = {
3030 'light' : [
3131 { scope : 'token.info-token' , settings : { foreground : '#316bcd' } } ,
3232 { scope : 'token.warn-token' , settings : { foreground : '#cd9731' } } ,
@@ -53,7 +53,7 @@ const defaultThemeColors: { [baseTheme: string]: ITextMateThemingRule[]; } = {
5353 ]
5454} ;
5555
56- function comma ( cursorNode : webTreeSitter . Node , position : vscode . Position ) {
56+ function insertComma ( cursorNode : webTreeSitter . Node , position : vscode . Position ) {
5757 return toPosition ( cursorNode . lastNamedChild ! . endPosition ) . isBefore ( position ) ? '' : ',' ;
5858}
5959
@@ -111,7 +111,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
111111 range : cursorRange ,
112112 kind : vscode . CompletionItemKind . Reference ,
113113 documentation : "Schema for VSCode's JSON TextMate grammars" ,
114- insertText : cursorName == 'schema' ? schema : `"${ schema } "${ comma ( cursorNode , position ) } ` ,
114+ insertText : cursorName == 'schema' ? schema : `"${ schema } "${ insertComma ( cursorNode , position ) } ` ,
115115 sortText : ' ' , // top
116116 } ) ;
117117 break ;
@@ -142,17 +142,20 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
142142 if ( Array . isArray ( grammars ) ) {
143143 const documentPath = document . uri . path ;
144144 for ( const grammar of grammars ) {
145- const grammarPath = vscode . Uri . joinPath ( packageUri ! , '..' , grammar . path ) . path ;
146- if ( grammarPath == documentPath ) {
147- completionItems . push ( {
148- label : {
149- label : grammar . scopeName || `source.${ grammar . language } ` ,
150- description : grammar . language ,
151- } ,
152- documentation : documentPath ,
153- range : cursorRange ,
154- kind : vscode . CompletionItemKind . Variable ,
155- } ) ;
145+ const relativePath = grammar . path ;
146+ if ( typeof relativePath === 'string' ) {
147+ const absolutePath = vscode . Uri . joinPath ( packageUri ! , '..' , relativePath ) . path ;
148+ if ( absolutePath == documentPath ) {
149+ completionItems . push ( {
150+ label : {
151+ label : grammar . scopeName || `source.${ grammar . language } ` ,
152+ description : grammar . language ,
153+ } ,
154+ documentation : documentPath ,
155+ range : cursorRange ,
156+ kind : vscode . CompletionItemKind . Variable ,
157+ } ) ;
158+ }
156159 }
157160 }
158161 }
@@ -166,52 +169,55 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
166169 }
167170 const documentPath = document . uri . path ;
168171 for ( const grammar of grammars ) {
169- const grammarPath = vscode . Uri . joinPath ( packageUri ! , '..' , grammar . path ) . path ;
170- if ( grammarPath == documentPath ) {
171- const languageId = grammar . language ;
172- if ( languageId ) {
173- const languages = contributes ! . languages ;
174- if ( Array . isArray ( languages ) ) {
175- for ( const language of languages ) {
176- if ( languageId == language . id ) {
177- const aliases = language . aliases ;
178- if ( Array . isArray ( aliases ) ) {
179- for ( const alias of aliases ) {
180- completionItems . push ( {
181- label : {
182- label : alias ,
183- description : grammar . scopeName || languageId ,
184- } ,
185- range : cursorRange ,
186- kind : vscode . CompletionItemKind . Text ,
187- } ) ;
172+ const relativePath = grammar . path ;
173+ if ( typeof relativePath === 'string' ) {
174+ const absolutePath = vscode . Uri . joinPath ( packageUri ! , '..' , relativePath ) . path ;
175+ if ( absolutePath == documentPath ) {
176+ const languageId = grammar . language ;
177+ if ( languageId ) {
178+ const languages = contributes ! . languages ;
179+ if ( Array . isArray ( languages ) ) {
180+ for ( const language of languages ) {
181+ if ( languageId == language . id ) {
182+ const aliases = language . aliases ;
183+ if ( Array . isArray ( aliases ) ) {
184+ for ( const alias of aliases ) {
185+ completionItems . push ( {
186+ label : {
187+ label : alias ,
188+ description : grammar . scopeName || languageId ,
189+ } ,
190+ range : cursorRange ,
191+ kind : vscode . CompletionItemKind . Text ,
192+ } ) ;
193+ }
188194 }
189195 }
190196 }
191197 }
192198 }
193- }
194- const displayName = packageJSON ! . displayName ;
195- if ( displayName ) {
196- completionItems . push ( {
197- label : {
198- label : displayName ,
199- description : packageJSON ! . name || languageId || grammar . scopeName ,
200- } ,
201- range : cursorRange ,
202- kind : vscode . CompletionItemKind . Text ,
203- } ) ;
204- }
205- const description = packageJSON ! . description ;
206- if ( description ) {
207- completionItems . push ( {
208- label : {
209- label : description ,
210- description : displayName || packageJSON ! . name || languageId || grammar . scopeName ,
211- } ,
212- range : cursorRange ,
213- kind : vscode . CompletionItemKind . Text ,
214- } ) ;
199+ const displayName = packageJSON ! . displayName ;
200+ if ( displayName ) {
201+ completionItems . push ( {
202+ label : {
203+ label : displayName ,
204+ description : packageJSON ! . name || languageId || grammar . scopeName ,
205+ } ,
206+ range : cursorRange ,
207+ kind : vscode . CompletionItemKind . Text ,
208+ } ) ;
209+ }
210+ const description = packageJSON ! . description ;
211+ if ( description ) {
212+ completionItems . push ( {
213+ label : {
214+ label : description ,
215+ description : displayName || packageJSON ! . name || languageId || grammar . scopeName ,
216+ } ,
217+ range : cursorRange ,
218+ kind : vscode . CompletionItemKind . Text ,
219+ } ) ;
220+ }
215221 }
216222 }
217223 }
@@ -259,7 +265,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
259265 range : cursorRange ,
260266 kind : vscode . CompletionItemKind . Property ,
261267 documentation : documentation ,
262- insertText : cursorName == 'repo' ? text : new vscode . SnippetString ( `"${ text } ": {$0}${ comma ( cursorNode , position ) } ` ) ,
268+ insertText : cursorName == 'repo' ? text : new vscode . SnippetString ( `"${ text } ": {$0}${ insertComma ( cursorNode , position ) } ` ) ,
263269 } ) ;
264270 }
265271 const documentation = new vscode . MarkdownString ( ) ;
@@ -275,7 +281,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
275281 insertText : cursorName == 'repo' ?
276282 "repo-item" :
277283 new vscode . SnippetString (
278- `"\${1:repo-item}": {$0}${ comma ( cursorNode , position ) } `
284+ `"\${1:repo-item}": {$0}${ insertComma ( cursorNode , position ) } `
279285 ) ,
280286 sortText : "~repo-item" , // bottom
281287 } ) ;
@@ -430,10 +436,10 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
430436 'hcDark' ,
431437 'hcLight' ,
432438 ] [ vscode . window . activeColorTheme . kind ] ;
433- const themeRules = defaultThemeColors [ baseTheme ] ;
434- for ( const themeRule of themeRules ) {
435- const scope = < string > themeRule . scope ;
436- const settings = themeRule . settings ;
439+ const builtInThemeRules = builtInThemeColors [ baseTheme ] ;
440+ for ( const builtInThemeRule of builtInThemeRules ) {
441+ const scope = < string > builtInThemeRule . scope ;
442+ const settings = builtInThemeRule . settings ;
437443 const documentation = new vscode . MarkdownString ( ) ;
438444 documentation . appendMarkdown (
439445 `Theme: \`${ baseTheme } \` \n` +
0 commit comments