Skip to content

Commit 43394de

Browse files
committed
more tests
1 parent 8bbe5ce commit 43394de

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

extensions/html-language-features/server/src/modes/javascriptSemanticTokens.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ export function getSemanticTokens(jsLanguageService: ts.LanguageService, current
3030
if (symbol) {
3131
let typeIdx = tokenFromDeclarationMapping[symbol.valueDeclaration.kind];
3232
let modifierSet = 0;
33-
if (node.parent && (<ts.NamedDeclaration>node.parent).name === node) {
34-
modifierSet = TokenModifier.declaration;
33+
if (node.parent) {
34+
const parentTypeIdx = tokenFromDeclarationMapping[node.parent.kind];
35+
if (parentTypeIdx === typeIdx && (<ts.NamedDeclaration>node.parent).name === node) {
36+
modifierSet = TokenModifier.declaration;
37+
}
3538
}
3639
if (typeIdx !== undefined) {
3740
resultTokens.push({ offset: node.getStart(), length: node.getWidth(), typeIdx, modifierSet });
@@ -130,5 +133,7 @@ const tokenFromDeclarationMapping: { [name: string]: TokenType } = {
130133
[ts.SyntaxKind.EnumDeclaration]: TokenType.enum,
131134
[ts.SyntaxKind.EnumMember]: TokenType.property,
132135
[ts.SyntaxKind.ClassDeclaration]: TokenType.property,
133-
[ts.SyntaxKind.MethodDeclaration]: TokenType.function
136+
[ts.SyntaxKind.MethodDeclaration]: TokenType.member,
137+
[ts.SyntaxKind.FunctionDeclaration]: TokenType.function,
138+
[ts.SyntaxKind.MethodSignature]: TokenType.member,
134139
};

extensions/html-language-features/server/src/test/semanticTokens.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,34 @@ suite('JavaScript Semantic Tokens', () => {
8383
];
8484
assertTokens(input, [
8585
t(3, 11, 3, 'function.declaration'), t(3, 15, 2, 'parameter.declaration'),
86-
t(4, 11, 3, 'function'), t(4, 15, 3, 'namespace'), t(4, 20, 3, 'member'), t(4, 24, 2, 'parameter')
86+
t(4, 11, 3, 'function'), t(4, 15, 4, 'variable'), t(4, 20, 3, 'member'), t(4, 24, 2, 'parameter')
8787
]);
8888
});
8989

90+
test('members', () => {
91+
const input = [
92+
/*0*/'<html>',
93+
/*1*/'<head>',
94+
/*2*/'<script>',
95+
/*3*/' class A {',
96+
/*4*/' static x = 9;',
97+
/*5*/' f = 9;',
98+
/*6*/' m() { return A.x; };',
99+
/*7*/' get s() { return this.f + this.m() }',
100+
/*8*/' }',
101+
/*9*/'</script>',
102+
/*10*/'</head>',
103+
/*11*/'</html>',
104+
];
105+
assertTokens(input, [
106+
t(3, 8, 1, 'class.declaration'),
107+
t(4, 11, 1, 'member.declaration'),
108+
t(5, 4, 1, 'property.declaration'),
109+
t(6, 4, 1, 'member.declaration'), t(6, 17, 1, 'class'), t(6, 19, 1, 'property'),
110+
t(7, 8, 1, 'member.declaration'),
111+
]);
112+
});
113+
114+
90115

91116
});

0 commit comments

Comments
 (0)