Skip to content

Commit 92d592c

Browse files
committed
Update logic for shouldSkipSemanticCheck to allow for quering semantic errors for JS files with @ts-check
1 parent f6324e7 commit 92d592c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/server/session.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ namespace ts.server {
2525
return ((1e9 * seconds) + nanoseconds) / 1000000.0;
2626
}
2727

28-
function shouldSkipSemanticCheck(project: Project) {
29-
if (project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) {
30-
return project.isJsOnlyProject();
31-
}
32-
else {
33-
// For configured projects, require that skipLibCheck be set also
34-
const options = project.getCompilerOptions();
35-
return options.skipLibCheck && !options.checkJs && project.isJsOnlyProject();
28+
function shouldSkipSemanticCheck(project: Project, file: NormalizedPath) {
29+
// For inferred (e.g. miscellaneous context in VS) and external projects (e.g. VS .csproj project) with only JS files
30+
// semantic errors in .d.ts files (e.g. ones added by automatic type acquisition) are not interesting.
31+
// We want to avoid the cost of querying for these errors all together, even if 'skipLibCheck' is not set.
32+
// We still want to check .js files (e.g. '// @ts-check' or '--checkJs' is set).
33+
if ((project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) &&
34+
project.isJsOnlyProject()) {
35+
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
36+
return scriptInfo && !scriptInfo.isJavaScript();
3637
}
38+
return false;
3739
}
3840

3941
interface FileStart {
@@ -489,7 +491,7 @@ namespace ts.server {
489491
private semanticCheck(file: NormalizedPath, project: Project) {
490492
try {
491493
let diags: Diagnostic[] = [];
492-
if (!shouldSkipSemanticCheck(project)) {
494+
if (!shouldSkipSemanticCheck(project, file)) {
493495
diags = project.getLanguageService().getSemanticDiagnostics(file);
494496
}
495497

@@ -597,7 +599,7 @@ namespace ts.server {
597599

598600
private getDiagnosticsWorker(args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) {
599601
const { project, file } = this.getFileAndProject(args);
600-
if (isSemantic && shouldSkipSemanticCheck(project)) {
602+
if (isSemantic && shouldSkipSemanticCheck(project, file)) {
601603
return [];
602604
}
603605
const scriptInfo = project.getScriptInfoForNormalizedPath(file);

0 commit comments

Comments
 (0)