From ef7d1136b80970f0be11ad37f66fe15fb583d672 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 18 Jun 2015 09:32:52 -0700 Subject: [PATCH] Make it so all our diagnostics APIs return an independent set of diagnostics. In order to get all diagnostics, you must call all the APIs. And no APIs return diagnostics produced by other APIs. This is how things were before hte addition of the getCompletionOptionsDiagnostics API, and i'm returning things to that state. --- src/compiler/checker.ts | 16 ++++++++-------- src/compiler/program.ts | 12 ++++-------- src/compiler/types.ts | 4 ++-- src/services/services.ts | 7 +++++-- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efc3e32166e..68a0916f743 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -159,6 +159,14 @@ namespace ts { } }; + let subtypeRelation: Map = {}; + let assignableRelation: Map = {}; + let identityRelation: Map = {}; + + initializeTypeChecker(); + + return checker; + function getEmitResolver(sourceFile?: SourceFile) { // Ensure we have all the type information in place for this file so that all the // emitter questions of this resolver will return the right information. @@ -4221,10 +4229,6 @@ namespace ts { // TYPE CHECKING - let subtypeRelation: Map = {}; - let assignableRelation: Map = {}; - let identityRelation: Map = {}; - function isTypeIdenticalTo(source: Type, target: Type): boolean { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); } @@ -13614,9 +13618,5 @@ namespace ts { return true; } } - - initializeTypeChecker(); - - return checker; } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 800e2238a54..87b7ab26c48 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -105,7 +105,7 @@ namespace ts { } export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] { - let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile)); + let diagnostics = program.getOptionsDiagnostics().concat(program.getSyntacticDiagnostics(sourceFile)).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile)); if (program.getCompilerOptions().declaration) { diagnostics.concat(program.getDeclarationDiagnostics(sourceFile)); @@ -177,10 +177,10 @@ namespace ts { getSourceFiles: () => files, getCompilerOptions: () => options, getSyntacticDiagnostics, + getOptionsDiagnostics, getGlobalDiagnostics, getSemanticDiagnostics, getDeclarationDiagnostics, - getCompilerOptionsDiagnostics, getTypeChecker, getClassifiableNames, getDiagnosticsProducingTypeChecker, @@ -311,19 +311,15 @@ namespace ts { } } - function getCompilerOptionsDiagnostics(): Diagnostic[] { + function getOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); return sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics(): Diagnostic[] { - let typeChecker = getDiagnosticsProducingTypeChecker(); - let allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, typeChecker.getGlobalDiagnostics()); - addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); - + addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics()); return sortAndDeduplicateDiagnostics(allDiagnostics); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c39426a2e22..f9a2fa3b7b4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1212,11 +1212,11 @@ namespace ts { */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; - getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + getOptionsDiagnostics(): Diagnostic[]; getGlobalDiagnostics(): Diagnostic[]; + getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; - /* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[]; /** * Gets a type checker that can be used to semantically analyze source fils in the program. diff --git a/src/services/services.ts b/src/services/services.ts index bab5b7707ef..f3d7a80302d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -973,6 +973,9 @@ namespace ts { getSyntacticDiagnostics(fileName: string): Diagnostic[]; getSemanticDiagnostics(fileName: string): Diagnostic[]; + + // TODO: Rename this to getProgramDiagnostics to better indicate that these are any + // diagnostics present for the program level, and not just 'options' diagnostics. getCompilerOptionsDiagnostics(): Diagnostic[]; /** @@ -1816,7 +1819,7 @@ namespace ts { var program = createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push(...program.getCompilerOptionsDiagnostics()); + diagnostics.push(...program.getOptionsDiagnostics()); } // Emit @@ -2796,7 +2799,7 @@ namespace ts { function getCompilerOptionsDiagnostics() { synchronizeHostData(); - return program.getGlobalDiagnostics(); + return program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics()); } /// Completion