From 8b449d1a0874b52b9a2d088ed1be6a7fd8d0051b Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Tue, 3 Dec 2019 10:52:47 +0100 Subject: [PATCH] semantic token test: fix length, skip unknown tokens --- .../src/colorizerTestMain.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/extensions/vscode-colorize-tests/src/colorizerTestMain.ts b/extensions/vscode-colorize-tests/src/colorizerTestMain.ts index 62aab90009d..e9536994cf7 100644 --- a/extensions/vscode-colorize-tests/src/colorizerTestMain.ts +++ b/extensions/vscode-colorize-tests/src/colorizerTestMain.ts @@ -8,8 +8,8 @@ import * as jsoncParser from 'jsonc-parser'; export function activate(context: vscode.ExtensionContext): any { - const tokenModifiers = ['static', 'abstract', 'deprecated', 'declaration', 'documentation', 'member', 'async']; const tokenTypes = ['types', 'structs', 'classes', 'interfaces', 'enums', 'parameterTypes', 'functions', 'variables']; + const tokenModifiers = ['static', 'abstract', 'deprecated', 'declaration', 'documentation', 'member', 'async']; const legend = new vscode.SemanticTokensLegend(tokenTypes, tokenModifiers); @@ -17,10 +17,12 @@ export function activate(context: vscode.ExtensionContext): any { provideSemanticTokens(document: vscode.TextDocument): vscode.ProviderResult { const builder = new vscode.SemanticTokensBuilder(); - function addToken(type: string, modifiers: string[], startLine: number, startCharacter: number, length: number) { + function addToken(value: string, startLine: number, startCharacter: number, length: number) { + const [type, ...modifiers] = value.split('.'); + let tokenType = legend.tokenTypes.indexOf(type); if (tokenType === -1) { - tokenType = 0; + return; } let tokenModifiers = 0; @@ -31,18 +33,17 @@ export function activate(context: vscode.ExtensionContext): any { } } + builder.push(startLine, startCharacter, length, tokenType, tokenModifiers); } const visitor: jsoncParser.JSONVisitor = { - onObjectProperty: (property: string, _offset: number, length: number, startLine: number, startCharacter: number) => { - const [type, ...modifiers] = property.split('.'); - addToken(type, modifiers, startLine, startCharacter, length); + onObjectProperty: (property: string, _offset: number, _length: number, startLine: number, startCharacter: number) => { + addToken(property, startLine, startCharacter, property.length + 2); }, onLiteralValue: (value: any, _offset: number, length: number, startLine: number, startCharacter: number) => { if (typeof value === 'string') { - const [type, ...modifiers] = value.split('.'); - addToken(type, modifiers, startLine, startCharacter, length); + addToken(value, startLine, startCharacter, length); } } };