mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #11404 from Microsoft/vladima/suppress-semantic-classifier-js
do not run semantic classification on non-ts-or-tsx files
This commit is contained in:
commit
7a67a3e724
@ -1109,7 +1109,7 @@ namespace ts.server {
|
||||
|
||||
private getNavigationBarItems(args: protocol.FileRequestArgs, simplifiedResult: boolean): protocol.NavigationBarItem[] | NavigationBarItem[] {
|
||||
const { file, project } = this.getFileAndProject(args);
|
||||
const items = project.getLanguageService().getNavigationBarItems(file);
|
||||
const items = project.getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(file);
|
||||
if (!items) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -1512,12 +1512,25 @@ namespace ts {
|
||||
return NavigationBar.getNavigationBarItems(sourceFile);
|
||||
}
|
||||
|
||||
function isTsOrTsxFile(fileName: string): boolean {
|
||||
const kind = getScriptKind(fileName, host);
|
||||
return kind === ScriptKind.TS || kind === ScriptKind.TSX;
|
||||
}
|
||||
|
||||
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
|
||||
if (!isTsOrTsxFile(fileName)) {
|
||||
// do not run semantic classification on non-ts-or-tsx files
|
||||
return [];
|
||||
}
|
||||
synchronizeHostData();
|
||||
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
|
||||
}
|
||||
|
||||
function getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications {
|
||||
if (!isTsOrTsxFile(fileName)) {
|
||||
// do not run semantic classification on non-ts-or-tsx files
|
||||
return { spans: [], endOfLineState: EndOfLineState.None };
|
||||
}
|
||||
synchronizeHostData();
|
||||
return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
|
||||
}
|
||||
|
||||
9
tests/cases/fourslash/semanticClassificationJs.ts
Normal file
9
tests/cases/fourslash/semanticClassificationJs.ts
Normal file
@ -0,0 +1,9 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
// @Filename: app.js
|
||||
//// function foo() {
|
||||
//// }
|
||||
//// let x = 1;
|
||||
|
||||
// no semantic classification in js file
|
||||
verify.semanticClassificationsAre();
|
||||
Loading…
x
Reference in New Issue
Block a user