diff --git a/src/server/session.ts b/src/server/session.ts index 742f8a3c228..57a3d0a5002 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -25,15 +25,17 @@ namespace ts.server { return ((1e9 * seconds) + nanoseconds) / 1000000.0; } - function shouldSkipSemanticCheck(project: Project) { - if (project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) { - return project.isJsOnlyProject(); - } - else { - // For configured projects, require that skipLibCheck be set also - const options = project.getCompilerOptions(); - return options.skipLibCheck && !options.checkJs && project.isJsOnlyProject(); + function shouldSkipSemanticCheck(project: Project, file: NormalizedPath) { + // For inferred (e.g. miscellaneous context in VS) and external projects (e.g. VS .csproj project) with only JS files + // semantic errors in .d.ts files (e.g. ones added by automatic type acquisition) are not interesting. + // We want to avoid the cost of querying for these errors all together, even if 'skipLibCheck' is not set. + // We still want to check .js files (e.g. '// @ts-check' or '--checkJs' is set). + if ((project.projectKind === ProjectKind.Inferred || project.projectKind === ProjectKind.External) && + project.isJsOnlyProject()) { + const scriptInfo = project.getScriptInfoForNormalizedPath(file); + return scriptInfo && !scriptInfo.isJavaScript(); } + return false; } interface FileStart { @@ -489,7 +491,7 @@ namespace ts.server { private semanticCheck(file: NormalizedPath, project: Project) { try { let diags: Diagnostic[] = []; - if (!shouldSkipSemanticCheck(project)) { + if (!shouldSkipSemanticCheck(project, file)) { diags = project.getLanguageService().getSemanticDiagnostics(file); } @@ -597,7 +599,7 @@ namespace ts.server { private getDiagnosticsWorker(args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => Diagnostic[], includeLinePosition: boolean) { const { project, file } = this.getFileAndProject(args); - if (isSemantic && shouldSkipSemanticCheck(project)) { + if (isSemantic && shouldSkipSemanticCheck(project, file)) { return []; } const scriptInfo = project.getScriptInfoForNormalizedPath(file);