mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(language-service): add methods for decoding classifications to public api (#62251)
Add methods for decoding classifications to public api for use in the language server PR Close #62251
This commit is contained in:
parent
9791ab1b6f
commit
b489f9fa8f
3 changed files with 24 additions and 1 deletions
|
|
@ -110,6 +110,9 @@ export interface NgLanguageService extends ts.LanguageService {
|
|||
): Promise<ApplyRefactoringResult | undefined>;
|
||||
|
||||
hasCodeFixesForErrorCode(errorCode: number): boolean;
|
||||
|
||||
getTokenTypeFromClassification(classification: number): number | undefined;
|
||||
getTokenModifierFromClassification(classification: number): number;
|
||||
}
|
||||
|
||||
export function isNgLanguageService(
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ import {
|
|||
} from './utils/ts_utils';
|
||||
import {getTypeCheckInfoAtPosition, isTypeScriptFile, TypeCheckInfo} from './utils';
|
||||
import {ActiveRefactoring, allRefactorings} from './refactorings/refactoring';
|
||||
import {getClassificationsForTemplate} from './semantic_tokens';
|
||||
import {getClassificationsForTemplate, TokenEncodingConsts} from './semantic_tokens';
|
||||
import {isExternalResource} from '@angular/compiler-cli/src/ngtsc/metadata';
|
||||
|
||||
type LanguageServiceConfig = Omit<PluginConfig, 'angularOnly'>;
|
||||
|
|
@ -363,6 +363,17 @@ export class LanguageService {
|
|||
}
|
||||
}
|
||||
|
||||
getTokenTypeFromClassification(classification: number): number | undefined {
|
||||
if (classification > TokenEncodingConsts.modifierMask) {
|
||||
return (classification >> TokenEncodingConsts.typeOffset) - 1;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getTokenModifierFromClassification(classification: number) {
|
||||
return classification & TokenEncodingConsts.modifierMask;
|
||||
}
|
||||
|
||||
getCompletionsAtPosition(
|
||||
fileName: string,
|
||||
position: number,
|
||||
|
|
|
|||
|
|
@ -149,6 +149,13 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
|
|||
}
|
||||
}
|
||||
|
||||
function getTokenTypeFromClassification(classification: number): number | undefined {
|
||||
return ngLS.getTokenTypeFromClassification(classification);
|
||||
}
|
||||
function getTokenModifierFromClassification(classification: number): number {
|
||||
return ngLS.getTokenModifierFromClassification(classification);
|
||||
}
|
||||
|
||||
function getCompletionsAtPosition(
|
||||
fileName: string,
|
||||
position: number,
|
||||
|
|
@ -371,6 +378,8 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
|
|||
findRenameLocations,
|
||||
getRenameInfo,
|
||||
getEncodedSemanticClassifications,
|
||||
getTokenTypeFromClassification,
|
||||
getTokenModifierFromClassification,
|
||||
getCompletionsAtPosition,
|
||||
getCompletionEntryDetails,
|
||||
getCompletionEntrySymbol,
|
||||
|
|
|
|||
Loading…
Reference in a new issue