From 37ba67ead0fe11fbc43e2f9521b81f20d0c1c800 Mon Sep 17 00:00:00 2001 From: Michael Zhao <44533763+Pistonight@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:14:34 -0800 Subject: [PATCH] expose getEncodedSemanticClassifications from TypeScript language service --- src/language/typescript/monaco.contribution.ts | 12 ++++++++++++ src/language/typescript/tsWorker.ts | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/language/typescript/monaco.contribution.ts b/src/language/typescript/monaco.contribution.ts index d272f375fa..4011ae3b9d 100644 --- a/src/language/typescript/monaco.contribution.ts +++ b/src/language/typescript/monaco.contribution.ts @@ -547,6 +547,18 @@ export interface TypeScriptWorker { * @returns `Promise<typescript.InlayHint[]>` */ provideInlayHints(fileName: string, start: number, end: number): Promise<ReadonlyArray<any>>; + + /** + * Get encoded semantic classifications in the range of the file. + * + * The returned number array is encoded as triples of [start, length, ClassificationType, ...]. + * @returns `Promise<typescript.Classifications | undefined>` + */ + getEncodedSemanticClassifications( + fileName: string, + start: number, + end: number + ): Promise<{ spans: number[] } | undefined>; } // --- TypeScript configuration and defaults --------- diff --git a/src/language/typescript/tsWorker.ts b/src/language/typescript/tsWorker.ts index c4f7d3eba0..b8190509f3 100644 --- a/src/language/typescript/tsWorker.ts +++ b/src/language/typescript/tsWorker.ts @@ -473,6 +473,21 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork return []; } } + + async getEncodedSemanticClassifications( + fileName: string, + start: number, + end: number + ): Promise<ts.Classifications | undefined> { + if (fileNameIsLib(fileName)) { + return undefined; + } + return this._languageService.getEncodedSemanticClassifications( + fileName, + { start, length: end - start }, + '2020' as ts.SemanticClassificationFormat + ); + } } export interface ICreateData {