Skip to content

Commit 473f651

Browse files
committed
Handle feedback
1 parent b8742c3 commit 473f651

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/services/classifier2020.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace ts.classifier.v2020 {
1818
}
1919

2020
/** This is mainly used internally for testing */
21-
export function getSemanticClassifications(program: Program, _cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): ClassifiedSpan[] {
22-
const classifications = getEncodedSemanticClassifications(program, _cancellationToken, sourceFile, span);
21+
export function getSemanticClassifications(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): ClassifiedSpan[] {
22+
const classifications = getEncodedSemanticClassifications(program, cancellationToken, sourceFile, span);
2323

2424
Debug.assert(classifications.spans.length % 3 === 0);
2525
const dense = classifications.spans;
@@ -34,32 +34,43 @@ namespace ts.classifier.v2020 {
3434
return result;
3535
}
3636

37-
export function getEncodedSemanticClassifications(program: Program, _cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): Classifications {
37+
export function getEncodedSemanticClassifications(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, span: TextSpan): Classifications {
3838
return {
39-
spans: getSemanticTokens(program, sourceFile, span),
39+
spans: getSemanticTokens(program, sourceFile, span, cancellationToken),
4040
endOfLineState: EndOfLineState.None
4141
};
4242
}
4343

44-
function getSemanticTokens(program: Program, sourceFile: SourceFile, span: TextSpan): number[] {
44+
function getSemanticTokens(program: Program, sourceFile: SourceFile, span: TextSpan, cancellationToken: CancellationToken): number[] {
4545
const resultTokens: number[] = [];
4646

4747
const collector = (node: Node, typeIdx: number, modifierSet: number) => {
4848
resultTokens.push(node.getStart(sourceFile), node.getWidth(sourceFile), ((typeIdx + 1) << TokenEncodingConsts.typeOffset) + modifierSet);
4949
};
5050

5151
if (program && sourceFile) {
52-
collectTokens(program, sourceFile, span, collector);
52+
collectTokens(program, sourceFile, span, collector, cancellationToken);
5353
}
5454
return resultTokens;
5555
}
5656

57-
function collectTokens(program: Program, sourceFile: SourceFile, span: TextSpan, collector: (node: Node, tokenType: number, tokenModifier: number) => void) {
57+
function collectTokens(program: Program, sourceFile: SourceFile, span: TextSpan, collector: (node: Node, tokenType: number, tokenModifier: number) => void, cancellationToken: CancellationToken) {
5858
const typeChecker = program.getTypeChecker();
5959

6060
let inJSXElement = false;
6161

6262
function visit(node: Node) {
63+
switch(node.kind) {
64+
case SyntaxKind.ModuleDeclaration:
65+
case SyntaxKind.ClassDeclaration:
66+
case SyntaxKind.InterfaceDeclaration:
67+
case SyntaxKind.FunctionDeclaration:
68+
case SyntaxKind.ClassExpression:
69+
case SyntaxKind.FunctionExpression:
70+
case SyntaxKind.ArrowFunction:
71+
if (cancellationToken.isCancellationRequested()) return;
72+
}
73+
6374
if (!node || !textSpanIntersectsWith(span, node.pos, node.getFullWidth()) || node.getFullWidth() === 0) {
6475
return;
6576
}
@@ -217,22 +228,6 @@ namespace ts.classifier.v2020 {
217228
return (isQualifiedName(node.parent) && node.parent.right === node) || (isPropertyAccessExpression(node.parent) && node.parent.name === node);
218229
}
219230

220-
const enum SemanticMeaning {
221-
None = 0x0,
222-
Value = 0x1,
223-
Type = 0x2,
224-
Namespace = 0x4,
225-
All = Value | Type | Namespace
226-
}
227-
228-
function getMeaningFromLocation(node: Node): SemanticMeaning {
229-
const f = (<any>ts).getMeaningFromLocation;
230-
if (typeof f === "function") {
231-
return f(node);
232-
}
233-
return SemanticMeaning.All;
234-
}
235-
236231
const tokenFromDeclarationMapping: { [name: string]: TokenType } = {
237232
[SyntaxKind.VariableDeclaration]: TokenType.variable,
238233
[SyntaxKind.Parameter]: TokenType.parameter,

0 commit comments

Comments
 (0)