@@ -12,30 +12,29 @@ export function getSemanticTokens(jsLanguageService: ts.LanguageService, current
1212 //https://ts-ast-viewer.com/#code/AQ0g2CmAuwGbALzAJwG4BQZQGNwEMBnQ4AQQEYBmYAb2C22zgEtJwATJVTRxgcwD27AQAp8AGmAAjAJS0A9POB8+7NQ168oscAJz5wANXwAnLug2bsJmAFcTAO2XAA1MHyvgu-UdOeWbOw8ViAAvpagocBAA
1313
1414 let resultTokens : SemanticTokenData [ ] = [ ] ;
15- const tokens = jsLanguageService . getSemanticClassifications ( fileName , { start : 0 , length : currentTextDocument . getText ( ) . length } ) ;
16- for ( let token of tokens ) {
17- const typeIdx = tokenFromClassificationMapping [ token . classificationType ] ;
18- if ( typeIdx !== undefined ) {
19- resultTokens . push ( { offset : token . textSpan . start , length : token . textSpan . length , typeIdx, modifierSet : 0 } ) ;
20- }
21- }
15+ // const tokens = jsLanguageService.getSemanticClassifications(fileName, { start: 0, length: currentTextDocument.getText().length });
16+ // for (let token of tokens) {
17+ // const typeIdx = tokenFromClassificationMapping[token.classificationType];
18+ // if (typeIdx !== undefined) {
19+ // resultTokens.push({ offset: token.textSpan.start, length: token.textSpan.length, typeIdx, modifierSet: 0 });
20+ // }
21+ // }
2222
2323 const program = jsLanguageService . getProgram ( ) ;
2424 if ( program ) {
2525 const typeChecker = program . getTypeChecker ( ) ;
2626
27-
2827 function visit ( node : ts . Node ) {
2928 if ( node . kind === ts . SyntaxKind . Identifier ) {
3029 const symbol = typeChecker . getSymbolAtLocation ( node ) ;
3130 if ( symbol ) {
3231 let typeIdx = tokenFromDeclarationMapping [ symbol . valueDeclaration . kind ] ;
3332 let modifierSet = 0 ;
34- if ( symbol . valueDeclaration === node . parent ) {
33+ if ( node . parent && ( < ts . NamedDeclaration > node . parent ) . name === node ) {
3534 modifierSet = TokenModifier . declaration ;
3635 }
3736 if ( typeIdx !== undefined ) {
38- resultTokens . push ( { offset : node . pos , length : node . end - node . pos , typeIdx, modifierSet } ) ;
37+ resultTokens . push ( { offset : node . getStart ( ) , length : node . getWidth ( ) , typeIdx, modifierSet } ) ;
3938 }
4039 }
4140 }
@@ -91,7 +90,7 @@ export function getSemanticTokenLegend() {
9190}
9291
9392
94- const tokenTypes : string [ ] = [ 'class' , 'enum' , 'interface' , 'namespace' , 'parameterType' , 'type' , 'parameter' , 'variable' , 'property' , 'constant' , 'function' ] ;
93+ const tokenTypes : string [ ] = [ 'class' , 'enum' , 'interface' , 'namespace' , 'parameterType' , 'type' , 'parameter' , 'variable' , 'property' , 'constant' , 'function' , 'member' ] ;
9594const tokenModifiers : string [ ] = [ 'declaration' , ] ;
9695
9796enum TokenType {
@@ -106,22 +105,22 @@ enum TokenType {
106105 'property' = 8 ,
107106 'constant' = 9 ,
108107 'function' = 10 ,
108+ 'member' = 11
109109}
110110
111111enum TokenModifier {
112- 'declaration' = 0x01 ,
113-
112+ 'declaration' = 0x01
114113}
115114
116- const tokenFromClassificationMapping : { [ name : string ] : TokenType } = {
117- [ ts . ClassificationTypeNames . className ] : TokenType . class ,
118- [ ts . ClassificationTypeNames . enumName ] : TokenType . enum ,
119- [ ts . ClassificationTypeNames . interfaceName ] : TokenType . interface ,
120- [ ts . ClassificationTypeNames . moduleName ] : TokenType . namespace ,
121- [ ts . ClassificationTypeNames . typeParameterName ] : TokenType . parameterType ,
122- [ ts . ClassificationTypeNames . typeAliasName ] : TokenType . type ,
123- [ ts . ClassificationTypeNames . parameterName ] : TokenType . parameter
124- } ;
115+ // const tokenFromClassificationMapping: { [name: string]: TokenType } = {
116+ // [ts.ClassificationTypeNames.className]: TokenType.class,
117+ // [ts.ClassificationTypeNames.enumName]: TokenType.enum,
118+ // [ts.ClassificationTypeNames.interfaceName]: TokenType.interface,
119+ // [ts.ClassificationTypeNames.moduleName]: TokenType.namespace,
120+ // [ts.ClassificationTypeNames.typeParameterName]: TokenType.parameterType,
121+ // [ts.ClassificationTypeNames.typeAliasName]: TokenType.type,
122+ // [ts.ClassificationTypeNames.parameterName]: TokenType.parameter
123+ // };
125124
126125const tokenFromDeclarationMapping : { [ name : string ] : TokenType } = {
127126 [ ts . SyntaxKind . VariableDeclaration ] : TokenType . variable ,
0 commit comments