Update logic for shouldSkipSemanticCheck to allow for quering semantic errors for JS files with @ts-check

This commit is contained in:
Mohamed Hegazy
2017-04-18 16:19:28 -07:00
parent f6324e7914
commit 92d592c23d

View File

@@ -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);