Skip to content

Commit ef7d113

Browse files
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.
1 parent 6db4faf commit ef7d113

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ namespace ts {
159159
}
160160
};
161161

162+
let subtypeRelation: Map<RelationComparisonResult> = {};
163+
let assignableRelation: Map<RelationComparisonResult> = {};
164+
let identityRelation: Map<RelationComparisonResult> = {};
165+
166+
initializeTypeChecker();
167+
168+
return checker;
169+
162170
function getEmitResolver(sourceFile?: SourceFile) {
163171
// Ensure we have all the type information in place for this file so that all the
164172
// emitter questions of this resolver will return the right information.
@@ -4221,10 +4229,6 @@ namespace ts {
42214229

42224230
// TYPE CHECKING
42234231

4224-
let subtypeRelation: Map<RelationComparisonResult> = {};
4225-
let assignableRelation: Map<RelationComparisonResult> = {};
4226-
let identityRelation: Map<RelationComparisonResult> = {};
4227-
42284232
function isTypeIdenticalTo(source: Type, target: Type): boolean {
42294233
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
42304234
}
@@ -13614,9 +13618,5 @@ namespace ts {
1361413618
return true;
1361513619
}
1361613620
}
13617-
13618-
initializeTypeChecker();
13619-
13620-
return checker;
1362113621
}
1362213622
}

src/compiler/program.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace ts {
105105
}
106106

107107
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] {
108-
let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
108+
let diagnostics = program.getOptionsDiagnostics().concat(program.getSyntacticDiagnostics(sourceFile)).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
109109

110110
if (program.getCompilerOptions().declaration) {
111111
diagnostics.concat(program.getDeclarationDiagnostics(sourceFile));
@@ -177,10 +177,10 @@ namespace ts {
177177
getSourceFiles: () => files,
178178
getCompilerOptions: () => options,
179179
getSyntacticDiagnostics,
180+
getOptionsDiagnostics,
180181
getGlobalDiagnostics,
181182
getSemanticDiagnostics,
182183
getDeclarationDiagnostics,
183-
getCompilerOptionsDiagnostics,
184184
getTypeChecker,
185185
getClassifiableNames,
186186
getDiagnosticsProducingTypeChecker,
@@ -311,19 +311,15 @@ namespace ts {
311311
}
312312
}
313313

314-
function getCompilerOptionsDiagnostics(): Diagnostic[] {
314+
function getOptionsDiagnostics(): Diagnostic[] {
315315
let allDiagnostics: Diagnostic[] = [];
316316
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
317317
return sortAndDeduplicateDiagnostics(allDiagnostics);
318318
}
319319

320320
function getGlobalDiagnostics(): Diagnostic[] {
321-
let typeChecker = getDiagnosticsProducingTypeChecker();
322-
323321
let allDiagnostics: Diagnostic[] = [];
324-
addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
325-
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
326-
322+
addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics());
327323
return sortAndDeduplicateDiagnostics(allDiagnostics);
328324
}
329325

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,11 @@ namespace ts {
12121212
*/
12131213
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
12141214

1215-
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
1215+
getOptionsDiagnostics(): Diagnostic[];
12161216
getGlobalDiagnostics(): Diagnostic[];
1217+
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
12171218
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
12181219
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
1219-
/* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[];
12201220

12211221
/**
12221222
* Gets a type checker that can be used to semantically analyze source fils in the program.

src/services/services.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ namespace ts {
973973

974974
getSyntacticDiagnostics(fileName: string): Diagnostic[];
975975
getSemanticDiagnostics(fileName: string): Diagnostic[];
976+
977+
// TODO: Rename this to getProgramDiagnostics to better indicate that these are any
978+
// diagnostics present for the program level, and not just 'options' diagnostics.
976979
getCompilerOptionsDiagnostics(): Diagnostic[];
977980

978981
/**
@@ -1816,7 +1819,7 @@ namespace ts {
18161819
var program = createProgram([inputFileName], options, compilerHost);
18171820

18181821
if (diagnostics) {
1819-
diagnostics.push(...program.getCompilerOptionsDiagnostics());
1822+
diagnostics.push(...program.getOptionsDiagnostics());
18201823
}
18211824

18221825
// Emit
@@ -2796,7 +2799,7 @@ namespace ts {
27962799

27972800
function getCompilerOptionsDiagnostics() {
27982801
synchronizeHostData();
2799-
return program.getGlobalDiagnostics();
2802+
return program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics());
28002803
}
28012804

28022805
/// Completion

0 commit comments

Comments
 (0)