Skip to content

Commit 8f08c2f

Browse files
committed
more tests
1 parent f24b58c commit 8f08c2f

4 files changed

Lines changed: 40 additions & 19 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ if (!ts.sys.fileExists(jquery_d_ts)) {
2424
jquery_d_ts = join(__dirname, '../../lib/jquery.d.ts'); // from source
2525
}
2626

27-
export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>, id: 'javascript' | 'typescript'): LanguageMode {
28-
let jsDocuments = getLanguageModelCache<TextDocument>(10, 60, document => documentRegions.get(document).getEmbeddedDocument('javascript'));
27+
export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>, languageId: 'javascript' | 'typescript'): LanguageMode {
28+
let jsDocuments = getLanguageModelCache<TextDocument>(10, 60, document => documentRegions.get(document).getEmbeddedDocument(languageId));
2929

30-
const workingFile = id === 'javascript' ? 'vscode://javascript/1.js' : 'vscode://javascript/2.ts'; // the same 'file' is used for all contents
30+
const workingFile = languageId === 'javascript' ? 'vscode://javascript/1.js' : 'vscode://javascript/2.ts'; // the same 'file' is used for all contents
3131

3232
let compilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es6.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic };
3333
let currentTextDocument: TextDocument;
@@ -72,7 +72,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
7272

7373
return {
7474
getId() {
75-
return id;
75+
return languageId;
7676
},
7777
doValidation(document: TextDocument): Diagnostic[] {
7878
updateCurrentTextDocument(document);
@@ -82,7 +82,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
8282
return {
8383
range: convertRange(currentTextDocument, diag),
8484
severity: DiagnosticSeverity.Error,
85-
source: 'js',
85+
source: languageId,
8686
message: ts.flattenDiagnosticMessageText(diag.messageText, '\n')
8787
};
8888
});
@@ -106,7 +106,7 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
106106
kind: convertKind(entry.kind),
107107
textEdit: TextEdit.replace(replaceRange, entry.name),
108108
data: { // data used for resolving item details (see 'doResolve')
109-
languageId: 'javascript',
109+
languageId,
110110
uri: document.uri,
111111
offset: offset
112112
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ export function getSemanticTokenLegend() {
6161
}
6262

6363

64-
const tokenTypes: string[] = ['class', 'enum', 'interface', 'namespace', 'parameterType', 'type', 'parameter', 'variable', 'property', 'constant', 'function', 'member'];
64+
const tokenTypes: string[] = ['class', 'enum', 'interface', 'namespace', 'typeParameter', 'type', 'parameter', 'variable', 'property', 'constant', 'function', 'member'];
6565
const tokenModifiers: string[] = ['declaration', 'static', 'async'];
6666

6767
enum TokenType {
6868
'class' = 0,
6969
'enum' = 1,
7070
'interface' = 2,
7171
'namespace' = 3,
72-
'parameterType' = 4,
72+
'typeParameter' = 4,
7373
'type' = 5,
7474
'parameter' = 6,
7575
'variable' = 7,
@@ -98,4 +98,7 @@ const tokenFromDeclarationMapping: { [name: string]: TokenType } = {
9898
[ts.SyntaxKind.MethodSignature]: TokenType.member,
9999
[ts.SyntaxKind.GetAccessor]: TokenType.property,
100100
[ts.SyntaxKind.PropertySignature]: TokenType.property,
101+
[ts.SyntaxKind.InterfaceDeclaration]: TokenType.interface,
102+
[ts.SyntaxKind.TypeAliasDeclaration]: TokenType.type,
103+
[ts.SyntaxKind.TypeParameter]: TokenType.typeParameter
101104
};

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function t(startLine: number, character: number, length: number, tokenClassifict
4646
return { startLine, character, length, tokenClassifiction };
4747
}
4848

49-
suite.skip('JavaScript Semantic Tokens', () => {
49+
suite('JavaScript Semantic Tokens', () => {
5050

5151
test('variables', () => {
5252
const input = [
@@ -133,20 +133,39 @@ suite('Type Semantic Tokens', () => {
133133
/*1*/'<head>',
134134
/*2*/'<script type="text/typescript">',
135135
/*3*/' interface Position { x: number, y: number };',
136-
/*4*/' const p = { x: 1, y: 2 }',
137-
/*5*/'</script>',
138-
/*6*/'</head>',
139-
/*7*/'</html>',
136+
/*4*/' const p = { x: 1, y: 2 } as Position;',
137+
/*5*/' const foo = (o: Position) => o.x + o.y;',
138+
/*6*/'</script>',
139+
/*7*/'</head>',
140+
/*8*/'</html>',
140141
];
141142
assertTokens(input, [
142-
t(3, 6, 1, 'variable.declaration'), t(3, 13, 2, 'variable.declaration'), t(3, 19, 1, 'variable'),
143-
t(5, 15, 1, 'variable.declaration'), t(5, 20, 2, 'variable'),
144-
t(6, 11, 1, 'variable.declaration'),
145-
t(7, 10, 2, 'variable')
143+
t(3, 12, 8, 'interface.declaration'), t(3, 23, 1, 'property.declaration'), t(3, 34, 1, 'property.declaration'),
144+
t(4, 8, 1, 'variable.declaration'), t(4, 30, 8, 'interface'),
145+
t(5, 8, 3, 'variable.declaration'), t(5, 15, 1, 'parameter.declaration'), t(5, 18, 8, 'interface'), t(5, 31, 1, 'parameter'), t(5, 33, 1, 'property'), t(5, 37, 1, 'parameter'), t(5, 39, 1, 'property')
146146
]);
147147
});
148148

149149

150+
test('type alias', () => {
151+
const input = [
152+
/*0*/'<html>',
153+
/*1*/'<head>',
154+
/*2*/'<script type="text/typescript">',
155+
/*3*/' type MyMap = Map<string, number>;',
156+
/*4*/' function f<T extends MyMap>(t: T | number) : T { ',
157+
/*5*/' return <T> <unknown> new Map<string, MyMap>();',
158+
/*6*/' }',
159+
/*7*/'</script>',
160+
/*8*/'</head>',
161+
/*9*/'</html>',
162+
];
163+
assertTokens(input, [
164+
t(3, 7, 5, 'type.declaration'), t(3, 15, 3, 'variable') /* to investiagte */,
165+
t(4, 11, 1, 'function.declaration'), t(4, 13, 1, 'typeParameter.declaration'), t(4, 23, 5, 'type'), t(4, 30, 1, 'parameter.declaration'), t(4, 33, 1, 'typeParameter'), t(4, 47, 1, 'typeParameter'),
166+
t(5, 12, 1, 'typeParameter'), t(5, 29, 3, 'variable'), t(5, 41, 5, 'type'),
167+
]);
168+
});
150169

151170

152171
});

src/vs/platform/theme/common/tokenClassificationRegistry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ function registerDefaultClassifications(): void {
378378
registerTokenType('class', nls.localize('class', "Style for classes."), [['entity.name.class']], 'type');
379379
registerTokenType('interface', nls.localize('interface', "Style for interfaces."), undefined, 'type');
380380
registerTokenType('enum', nls.localize('enum', "Style for enums."), undefined, 'type');
381-
registerTokenType('parameterType', nls.localize('parameterType', "Style for parameter types."), undefined, 'type');
381+
registerTokenType('typeParameter', nls.localize('typeParameter', "Style for type parameters."), undefined, 'type');
382382

383383
registerTokenType('function', nls.localize('function', "Style for functions"), [['entity.name.function'], ['support.function']]);
384384
registerTokenType('member', nls.localize('member', "Style for member"), [['entity.name.function'], ['support.function']]);
@@ -395,7 +395,6 @@ function registerDefaultClassifications(): void {
395395

396396
tokenClassificationRegistry.registerTokenModifier('declaration', nls.localize('declaration', "Style for all symbol declarations."), undefined);
397397
tokenClassificationRegistry.registerTokenModifier('documentation', nls.localize('documentation', "Style to use for references in documentation."), undefined);
398-
//tokenClassificationRegistry.registerTokenModifier('member', nls.localize('member', "Style to use for member functions, variables (fields) and types."), undefined);
399398
tokenClassificationRegistry.registerTokenModifier('static', nls.localize('static', "Style to use for symbols that are static."), undefined);
400399
tokenClassificationRegistry.registerTokenModifier('abstract', nls.localize('abstract', "Style to use for symbols that are abstract."), undefined);
401400
tokenClassificationRegistry.registerTokenModifier('deprecated', nls.localize('deprecated', "Style to use for symbols that are deprecated."), undefined);

0 commit comments

Comments
 (0)