Skip to content

Commit 7a67a3e

Browse files
authored
Merge pull request #11404 from Microsoft/vladima/suppress-semantic-classifier-js
do not run semantic classification on non-ts-or-tsx files
2 parents f442480 + 59c0143 commit 7a67a3e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ namespace ts.server {
11091109

11101110
private getNavigationBarItems(args: protocol.FileRequestArgs, simplifiedResult: boolean): protocol.NavigationBarItem[] | NavigationBarItem[] {
11111111
const { file, project } = this.getFileAndProject(args);
1112-
const items = project.getLanguageService().getNavigationBarItems(file);
1112+
const items = project.getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(file);
11131113
if (!items) {
11141114
return undefined;
11151115
}

src/services/services.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,12 +1512,25 @@ namespace ts {
15121512
return NavigationBar.getNavigationBarItems(sourceFile);
15131513
}
15141514

1515+
function isTsOrTsxFile(fileName: string): boolean {
1516+
const kind = getScriptKind(fileName, host);
1517+
return kind === ScriptKind.TS || kind === ScriptKind.TSX;
1518+
}
1519+
15151520
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
1521+
if (!isTsOrTsxFile(fileName)) {
1522+
// do not run semantic classification on non-ts-or-tsx files
1523+
return [];
1524+
}
15161525
synchronizeHostData();
15171526
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
15181527
}
15191528

15201529
function getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications {
1530+
if (!isTsOrTsxFile(fileName)) {
1531+
// do not run semantic classification on non-ts-or-tsx files
1532+
return { spans: [], endOfLineState: EndOfLineState.None };
1533+
}
15211534
synchronizeHostData();
15221535
return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
15231536
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: app.js
4+
//// function foo() {
5+
//// }
6+
//// let x = 1;
7+
8+
// no semantic classification in js file
9+
verify.semanticClassificationsAre();

0 commit comments

Comments
 (0)