Skip to content

Commit

Permalink
expose getEncodedSemanticClassifications from TypeScript language ser…
Browse files Browse the repository at this point in the history
…vice
  • Loading branch information
Pistonight committed Dec 18, 2024
1 parent a4b088e commit 37ba67e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/language/typescript/monaco.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------
Expand Down
15 changes: 15 additions & 0 deletions src/language/typescript/tsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 37ba67e

Please sign in to comment.