expose getEncodedSemanticClassifications from TypeScript language service

This commit is contained in:
Michael Zhao 2024-12-17 18:14:34 -08:00
parent a4b088e410
commit 37ba67ead0
2 changed files with 27 additions and 0 deletions

View file

@ -547,6 +547,18 @@ export interface TypeScriptWorker {
* @returns `Promise<typescript.InlayHint[]>` * @returns `Promise<typescript.InlayHint[]>`
*/ */
provideInlayHints(fileName: string, start: number, end: number): Promise<ReadonlyArray<any>>; 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 --------- // --- TypeScript configuration and defaults ---------

View file

@ -473,6 +473,21 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
return []; 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 { export interface ICreateData {