@@ -100,7 +100,11 @@ function proxyLanguageServiceForGlint<T>(
100100 // case 'getDefinitionAndBoundSpan': return getDefinitionAndBoundSpan(ts, language, languageService, glintOptions, asScriptId, target[p]);
101101 // case 'getQuickInfoAtPosition': return getQuickInfoAtPosition(ts, target, target[p]);
102102 // TS plugin only
103- // case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
103+
104+ // Left as an example in case we want to augment semantic classification in .gts files.
105+ // e.g. Vue does this to semantically classify Component names as `class` tokens.
106+ // case 'getEncodedSemanticClassifications':
107+ // return getEncodedSemanticClassifications(ts, language, target, asScriptId, target[p]);
104108
105109 case 'getSemanticDiagnostics' :
106110 return getSemanticDiagnostics ( ts , language , languageService , asScriptId , target [ p ] ) ;
@@ -203,3 +207,37 @@ function getSemanticDiagnostics<T>(
203207 return augmentedTsDiagnostics ;
204208 } ;
205209}
210+
211+ const windowsPathReg = / \\ / g;
212+
213+ /**
214+ * Return semantic tokens for semantic highlighting:
215+ * https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
216+ function getEncodedSemanticClassifications<T>(
217+ ts: typeof import('typescript'),
218+ language: any, // Language<T>,
219+ languageService: ts.LanguageService,
220+ asScriptId: (fileName: string) => T,
221+ getEncodedSemanticClassifications: ts.LanguageService['getEncodedSemanticClassifications'],
222+ ): ts.LanguageService['getEncodedSemanticClassifications'] {
223+ return (filePath, span, format) => {
224+ const fileName = filePath.replace(windowsPathReg, '/');
225+ const result = getEncodedSemanticClassifications(fileName, span, format);
226+ const sourceScript = language.scripts.get(asScriptId(fileName));
227+ const root = sourceScript?.generated?.root;
228+ if (root instanceof VirtualGtsCode) {
229+ // This would remove all semantic highlighting from .gts files, including the TS parts
230+ // outside of the `<template>` tags, which is probably undesirable.
231+ // result.spans = [];
232+
233+ // We can push span to the end of the array to override previous entries.
234+ // result.spans.push(
235+ // 0,
236+ // 100,
237+ // 256, // class
238+ // );
239+ }
240+ return result;
241+ };
242+ }
243+ */
0 commit comments