@@ -20,6 +20,7 @@ import {GetComponentsWithTemplateFile, GetTcbParams, GetTcbRequest, GetTcbRespon
20
20
import { readNgCompletionData , tsCompletionEntryToLspCompletionItem } from './completion' ;
21
21
import { tsDiagnosticToLspDiagnostic } from './diagnostic' ;
22
22
import { getHTMLVirtualContent } from './embedded_support' ;
23
+ import { getSemanticTokens } from './semantic_tokens' ;
23
24
import { ServerHost } from './server_host' ;
24
25
import { documentationToMarkdown } from './text_render' ;
25
26
import { filePathToUri , getMappedDefinitionInfo , isConfiguredProject , isDebugMode , lspPositionToTsPosition , lspRangeToTsPositions , MruTracker , tsDisplayPartsToText , tsFileTextChangesToLspWorkspaceEdit , tsTextSpanToLspRange , uriToFilePath } from './utils' ;
@@ -217,8 +218,38 @@ export class Session {
217
218
conn . onSignatureHelp ( p => this . onSignatureHelp ( p ) ) ;
218
219
conn . onCodeAction ( p => this . onCodeAction ( p ) ) ;
219
220
conn . onCodeActionResolve ( async p => await this . onCodeActionResolve ( p ) ) ;
221
+ conn . onRequest ( lsp . SemanticTokensRequest . type , p => this . onSemanticTokensRequest ( p ) ) ;
222
+ conn . onRequest ( lsp . SemanticTokensRangeRequest . type , p => this . onSemanticTokensRangeRequest ( p ) ) ;
220
223
}
221
224
225
+ private onSemanticTokensRequest ( params : lsp . SemanticTokensParams ) : lsp . SemanticTokens | null {
226
+ const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
227
+ if ( lsInfo === null ) {
228
+ return null ;
229
+ }
230
+ const { languageService, scriptInfo} = lsInfo ;
231
+ const span = { start : 0 , length : scriptInfo . getSnapshot ( ) . getLength ( ) } ;
232
+ const classifications = languageService . getEncodedSemanticClassifications (
233
+ scriptInfo . fileName , span , ts . SemanticClassificationFormat . TwentyTwenty ) ;
234
+ return getSemanticTokens ( classifications , scriptInfo ) ;
235
+ }
236
+
237
+ private onSemanticTokensRangeRequest ( params : lsp . SemanticTokensRangeParams ) : lsp . SemanticTokens
238
+ | null {
239
+ const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
240
+ if ( lsInfo === null ) {
241
+ return null ;
242
+ }
243
+ const { languageService, scriptInfo} = lsInfo ;
244
+ const start = lspPositionToTsPosition ( lsInfo . scriptInfo , params . range . start ) ;
245
+ const end = lspPositionToTsPosition ( lsInfo . scriptInfo , params . range . end ) ;
246
+ const span = { start, length : end - start } ;
247
+ const classifications = languageService . getEncodedSemanticClassifications (
248
+ scriptInfo . fileName , span , ts . SemanticClassificationFormat . TwentyTwenty ) ;
249
+ return getSemanticTokens ( classifications , scriptInfo ) ;
250
+ }
251
+
252
+
222
253
private onCodeAction ( params : lsp . CodeActionParams ) : lsp . CodeAction [ ] | null {
223
254
const filePath = uriToFilePath ( params . textDocument . uri ) ;
224
255
const lsInfo = this . getLSAndScriptInfo ( params . textDocument ) ;
@@ -809,6 +840,17 @@ export class Session {
809
840
// [here](https://github.com/angular/vscode-ng-language-service/issues/1828)
810
841
codeActionKinds : [ lsp . CodeActionKind . QuickFix ] ,
811
842
} ,
843
+ semanticTokensProvider : {
844
+ documentSelector : null ,
845
+ legend : {
846
+ tokenTypes : [
847
+ 'class' ,
848
+ ] ,
849
+ tokenModifiers : [ ] ,
850
+ } ,
851
+ full : true ,
852
+ range : true
853
+ }
812
854
} ,
813
855
serverOptions,
814
856
} ;
0 commit comments