diff --git a/internal/compiler/program.go b/internal/compiler/program.go index a9a6b47f3e..4f15f54766 100644 --- a/internal/compiler/program.go +++ b/internal/compiler/program.go @@ -1031,7 +1031,10 @@ func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic { return nil } - pool := p.checkerPool.(*checkerPool) + pool, ok := p.checkerPool.(*checkerPool) + if !ok { + return nil // !!! Global diagnostics in the editor? + } globalDiagnostics := make([][]*ast.Diagnostic, len(pool.checkers)) pool.forEachCheckerParallel(func(idx int, checker *checker.Checker) { @@ -1045,17 +1048,6 @@ func (p *Program) GetDeclarationDiagnostics(ctx context.Context, sourceFile *ast return p.collectDiagnostics(ctx, sourceFile, true /*concurrent*/, p.getDeclarationDiagnosticsForFile) } -func (p *Program) GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic { - return SortAndDeduplicateDiagnostics(core.Concatenate(p.GetGlobalDiagnostics(ctx), p.getOptionsDiagnosticsOfConfigFile())) -} - -func (p *Program) getOptionsDiagnosticsOfConfigFile() []*ast.Diagnostic { - if p.Options() == nil || p.Options().ConfigFilePath == "" { - return nil - } - return p.GetConfigFileParsingDiagnostics() -} - func FilterNoEmitSemanticDiagnostics(diagnostics []*ast.Diagnostic, options *core.CompilerOptions) []*ast.Diagnostic { if !options.NoEmit.IsTrue() { return diagnostics @@ -1445,7 +1437,6 @@ type ProgramLike interface { GetConfigFileParsingDiagnostics() []*ast.Diagnostic GetSyntacticDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic GetBindDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic - GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic GetProgramDiagnostics() []*ast.Diagnostic GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic GetSemanticDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic @@ -1494,18 +1485,16 @@ func GetDiagnosticsOfAnyProgram( allDiagnostics = append(allDiagnostics, program.GetProgramDiagnostics()...) if len(allDiagnostics) == configFileParsingDiagnosticsLength { - // Options diagnostics include global diagnostics (even though we collect them separately), - // and global diagnostics create checkers, which then bind all of the files. Do this binding - // early so we can track the time. + // Do binding early so we can track the time. getBindDiagnostics(ctx, file) - allDiagnostics = append(allDiagnostics, program.GetOptionsDiagnostics(ctx)...) - if program.Options().ListFilesOnly.IsFalseOrUnknown() { allDiagnostics = append(allDiagnostics, program.GetGlobalDiagnostics(ctx)...) if len(allDiagnostics) == configFileParsingDiagnosticsLength { allDiagnostics = append(allDiagnostics, getSemanticDiagnostics(ctx, file)...) + // Ask for the global diagnostics again (they were empty above); we may have found new during checking, e.g. missing globals. + allDiagnostics = append(allDiagnostics, program.GetGlobalDiagnostics(ctx)...) } if (skipNoEmitCheckForDtsDiagnostics || program.Options().NoEmit.IsTrue()) && program.Options().GetEmitDeclarations() && len(allDiagnostics) == configFileParsingDiagnosticsLength { diff --git a/internal/execute/incremental/program.go b/internal/execute/incremental/program.go index 2d5e595a6b..08a1aee121 100644 --- a/internal/execute/incremental/program.go +++ b/internal/execute/incremental/program.go @@ -132,12 +132,6 @@ func (p *Program) GetBindDiagnostics(ctx context.Context, file *ast.SourceFile) return p.program.GetBindDiagnostics(ctx, file) } -// GetOptionsDiagnostics implements compiler.AnyProgram interface. -func (p *Program) GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic { - p.panicIfNoProgram("GetOptionsDiagnostics") - return p.program.GetOptionsDiagnostics(ctx) -} - func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic { p.panicIfNoProgram("GetProgramDiagnostics") return p.program.GetProgramDiagnostics() @@ -365,7 +359,6 @@ func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler len(program.GetConfigFileParsingDiagnostics()) > 0 || len(program.GetSyntacticDiagnostics(ctx, nil)) > 0 || len(program.GetProgramDiagnostics()) > 0 || - len(program.GetOptionsDiagnostics(ctx)) > 0 || len(program.GetGlobalDiagnostics(ctx)) > 0 { p.snapshot.hasErrors = core.TSTrue // Dont need to encode semantic errors state since the syntax and program diagnostics are encoded as present diff --git a/testdata/baselines/reference/tsbuild/configFileErrors/reports-syntax-errors-in-config-file.js b/testdata/baselines/reference/tsbuild/configFileErrors/reports-syntax-errors-in-config-file.js index 23310d06e4..fa4e984be8 100644 --- a/testdata/baselines/reference/tsbuild/configFileErrors/reports-syntax-errors-in-config-file.js +++ b/testdata/baselines/reference/tsbuild/configFileErrors/reports-syntax-errors-in-config-file.js @@ -69,7 +69,7 @@ exports.bar = bar; function bar() { } //// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b8af959ef8294c415b0415508643e446-export function foo() { }","signature":"7ffb4ea6089b1a385965a214ba412941-export declare function foo(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true},"semanticDiagnosticsPerFile":[1,2,3],"latestChangedDtsFile":"./b.d.ts"} +{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b8af959ef8294c415b0415508643e446-export function foo() { }","signature":"7ffb4ea6089b1a385965a214ba412941-export declare function foo(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true},"latestChangedDtsFile":"./b.d.ts"} //// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -130,20 +130,15 @@ function bar() { } "options": { "composite": true }, - "semanticDiagnosticsPerFile": [ - "lib.d.ts", - "./a.ts", - "./b.ts" - ], "latestChangedDtsFile": "./b.d.ts", - "size": 1345 + "size": 1308 } tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts +*refresh* /home/src/tslibs/TS/Lib/lib.d.ts +*refresh* /home/src/workspaces/project/a.ts +*refresh* /home/src/workspaces/project/b.ts Signatures:: (stored at emit) /home/src/workspaces/project/a.ts (stored at emit) /home/src/workspaces/project/b.ts @@ -175,9 +170,6 @@ Found 1 error in tsconfig.json:7 tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts Signatures:: @@ -209,7 +201,7 @@ function foo() { } function fooBar() { } //// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* -{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"12981c250647eb82bb45c5fb79732976-export function foo() { }export function fooBar() { }","signature":"f3ff291f5185ac75eeeb6de19fc28a01-export declare function foo(): void;\nexport declare function fooBar(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true,"declaration":true},"semanticDiagnosticsPerFile":[1,2,3],"latestChangedDtsFile":"./a.d.ts"} +{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"12981c250647eb82bb45c5fb79732976-export function foo() { }export function fooBar() { }","signature":"f3ff291f5185ac75eeeb6de19fc28a01-export declare function foo(): void;\nexport declare function fooBar(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true,"declaration":true},"latestChangedDtsFile":"./a.d.ts"} //// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified* { "version": "FakeTSVersion", @@ -271,20 +263,13 @@ function fooBar() { } "composite": true, "declaration": true }, - "semanticDiagnosticsPerFile": [ - "lib.d.ts", - "./a.ts", - "./b.ts" - ], "latestChangedDtsFile": "./a.d.ts", - "size": 1433 + "size": 1396 } tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts Signatures:: (computed .d.ts) /home/src/workspaces/project/a.ts @@ -305,9 +290,6 @@ Found 1 error in tsconfig.json:7 tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts Signatures:: @@ -394,7 +376,4 @@ Output:: tsconfig.json:: SemanticDiagnostics:: -*refresh* /home/src/tslibs/TS/Lib/lib.d.ts -*refresh* /home/src/workspaces/project/a.ts -*refresh* /home/src/workspaces/project/b.ts Signatures:: diff --git a/testdata/baselines/reference/tsbuildWatch/configFileErrors/reports-syntax-errors-in-config-file.js b/testdata/baselines/reference/tsbuildWatch/configFileErrors/reports-syntax-errors-in-config-file.js index 1ae2b8dea6..ab961f7a18 100644 --- a/testdata/baselines/reference/tsbuildWatch/configFileErrors/reports-syntax-errors-in-config-file.js +++ b/testdata/baselines/reference/tsbuildWatch/configFileErrors/reports-syntax-errors-in-config-file.js @@ -70,7 +70,7 @@ exports.bar = bar; function bar() { } //// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new* -{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b8af959ef8294c415b0415508643e446-export function foo() { }","signature":"7ffb4ea6089b1a385965a214ba412941-export declare function foo(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true},"semanticDiagnosticsPerFile":[1,2,3],"latestChangedDtsFile":"./b.d.ts"} +{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"b8af959ef8294c415b0415508643e446-export function foo() { }","signature":"7ffb4ea6089b1a385965a214ba412941-export declare function foo(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true},"latestChangedDtsFile":"./b.d.ts"} //// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new* { "version": "FakeTSVersion", @@ -131,20 +131,15 @@ function bar() { } "options": { "composite": true }, - "semanticDiagnosticsPerFile": [ - "lib.d.ts", - "./a.ts", - "./b.ts" - ], "latestChangedDtsFile": "./b.d.ts", - "size": 1345 + "size": 1308 } tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts +*refresh* /home/src/tslibs/TS/Lib/lib.d.ts +*refresh* /home/src/workspaces/project/a.ts +*refresh* /home/src/workspaces/project/b.ts Signatures:: (stored at emit) /home/src/workspaces/project/a.ts (stored at emit) /home/src/workspaces/project/b.ts @@ -176,9 +171,6 @@ Output:: tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts Signatures:: @@ -210,7 +202,7 @@ function foo() { } function fooBar() { } //// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified* -{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"12981c250647eb82bb45c5fb79732976-export function foo() { }export function fooBar() { }","signature":"f3ff291f5185ac75eeeb6de19fc28a01-export declare function foo(): void;\nexport declare function fooBar(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true,"declaration":true},"semanticDiagnosticsPerFile":[1,2,3],"latestChangedDtsFile":"./a.d.ts"} +{"version":"FakeTSVersion","errors":true,"root":[[2,3]],"fileNames":["lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"12981c250647eb82bb45c5fb79732976-export function foo() { }export function fooBar() { }","signature":"f3ff291f5185ac75eeeb6de19fc28a01-export declare function foo(): void;\nexport declare function fooBar(): void;\n","impliedNodeFormat":1},{"version":"492f7ec5be310332dc7e2ef503772d24-export function bar() { }","signature":"2f1e9992435d5724d3e1da8bdbc17eae-export declare function bar(): void;\n","impliedNodeFormat":1}],"options":{"composite":true,"declaration":true},"latestChangedDtsFile":"./a.d.ts"} //// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified* { "version": "FakeTSVersion", @@ -272,20 +264,13 @@ function fooBar() { } "composite": true, "declaration": true }, - "semanticDiagnosticsPerFile": [ - "lib.d.ts", - "./a.ts", - "./b.ts" - ], "latestChangedDtsFile": "./a.d.ts", - "size": 1433 + "size": 1396 } tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts +*refresh* /home/src/workspaces/project/a.ts Signatures:: (computed .d.ts) /home/src/workspaces/project/a.ts @@ -307,9 +292,6 @@ Output:: tsconfig.json:: SemanticDiagnostics:: -*not cached* /home/src/tslibs/TS/Lib/lib.d.ts -*not cached* /home/src/workspaces/project/a.ts -*not cached* /home/src/workspaces/project/b.ts Signatures:: @@ -399,7 +381,4 @@ Output:: tsconfig.json:: SemanticDiagnostics:: -*refresh* /home/src/tslibs/TS/Lib/lib.d.ts -*refresh* /home/src/workspaces/project/a.ts -*refresh* /home/src/workspaces/project/b.ts Signatures::