From f1f652ccc191d40f06a84a4b468b9cf09f9406c6 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 10 Jan 2020 15:39:42 +0100 Subject: [PATCH] polish html-js sem highlighting --- .../src/modes/javascriptSemanticTokens.ts | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts b/extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts index 7e4deafa262..9a1f394977a 100644 --- a/extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts +++ b/extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts @@ -55,37 +55,42 @@ export function getSemanticTokens(jsLanguageService: ts.LanguageService, current return resultTokens; } +enum TokenType { + 'class', + 'enum', + 'interface', + 'namespace', + 'typeParameter', + 'type', + 'parameter', + 'variable', + 'property', + 'constant', + 'function', + 'member', + _sentinel +} + + +enum TokenModifier { + 'declaration', + 'static', + 'async', + _sentinel +} export function getSemanticTokenLegend() { + const tokenTypes = []; + for (let i = 0; i < TokenType._sentinel; i++) { + tokenTypes.push(TokenType[i]); + } + const tokenModifiers = []; + for (let i = 0; i < TokenModifier._sentinel; i++) { + tokenModifiers.push(TokenModifier[i]); + } return { types: tokenTypes, modifiers: tokenModifiers }; } - -const tokenTypes: string[] = ['class', 'enum', 'interface', 'namespace', 'typeParameter', 'type', 'parameter', 'variable', 'property', 'constant', 'function', 'member']; -const tokenModifiers: string[] = ['declaration', 'static', 'async']; - -const enum TokenType { - 'class' = 0, - 'enum' = 1, - 'interface' = 2, - 'namespace' = 3, - 'typeParameter' = 4, - 'type' = 5, - 'parameter' = 6, - 'variable' = 7, - 'property' = 8, - 'constant' = 9, - 'function' = 10, - 'member' = 11 -} - - -const enum TokenModifier { - 'declaration' = 0x01, - 'static' = 0x02, - 'async' = 0x04, -} - const tokenFromDeclarationMapping: { [name: string]: TokenType } = { [ts.SyntaxKind.VariableDeclaration]: TokenType.variable, [ts.SyntaxKind.Parameter]: TokenType.parameter,