Skip to content

Commit 7376eb2

Browse files
authored
Handle processing diagnostics similar to Strada (#1628)
1 parent e0df534 commit 7376eb2

11 files changed

+250
-62
lines changed

internal/compiler/program.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ func (p *Program) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast.
424424
}
425425

426426
func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic {
427-
return SortAndDeduplicateDiagnostics(slices.Concat(p.programDiagnostics, p.includeProcessor.getDiagnostics(p).GetDiagnostics()))
427+
return SortAndDeduplicateDiagnostics(slices.Concat(
428+
p.programDiagnostics,
429+
p.includeProcessor.getDiagnostics(p).GetGlobalDiagnostics()))
428430
}
429431

430432
func (p *Program) getSourceFilesToEmit(targetSourceFile *ast.SourceFile, forceDtsEmit bool) []*ast.SourceFile {
@@ -1024,7 +1026,8 @@ func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, so
10241026
fileChecker, done = p.checkerPool.GetCheckerForFile(ctx, sourceFile)
10251027
defer done()
10261028
}
1027-
diags := slices.Clip(sourceFile.BindDiagnostics())
1029+
diags := slices.Clip(p.includeProcessor.getDiagnostics(p).GetDiagnosticsForFile(sourceFile.FileName()))
1030+
diags = append(diags, sourceFile.BindDiagnostics()...)
10281031
checkers, closeCheckers := p.checkerPool.GetAllCheckers(ctx)
10291032
defer closeCheckers()
10301033

internal/execute/tsctests/tscbuild_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ func TestBuildDemoProject(t *testing.T) {
556556
commandLineArgs: []string{"--b", "--verbose"},
557557
},
558558
{
559-
// !!! sheetal - this has missing errors from strada about files not in rootDir (3) and value is declared but not used (1)
559+
// !!! sheetal - this has missing errors from strada about files not in rootDir (3)
560560
subScenario: "in bad-ref branch reports the error about files not in rootDir at the import location",
561561
files: getBuildDemoFileMap(func(files FileMap) {
562562
files["/user/username/projects/demo/core/utilities.ts"] = `import * as A from '../animals'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/processingDiagnosticSkipLibCheck.ts] ////
2+
3+
//// [index.d.ts]
4+
/// <reference types="cookie-session"/>
5+
export const foo = 1;
6+
7+
//// [package.json]
8+
{
9+
"name": "foo",
10+
"version": "1.0.0",
11+
"types": "index.d.ts"
12+
}
13+
//// [index.ts]
14+
import { foo } from 'foo';
15+
const y = foo;
16+
17+
18+
//// [index.js]
19+
"use strict";
20+
Object.defineProperty(exports, "__esModule", { value: true });
21+
const foo_1 = require("foo");
22+
const y = foo_1.foo;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/processingDiagnosticSkipLibCheck.ts] ////
2+
3+
=== /index.ts ===
4+
import { foo } from 'foo';
5+
>foo : Symbol(foo, Decl(index.ts, 0, 8))
6+
7+
const y = foo;
8+
>y : Symbol(y, Decl(index.ts, 1, 5))
9+
>foo : Symbol(foo, Decl(index.ts, 0, 8))
10+
11+
=== /node_modules/foo/index.d.ts ===
12+
/// <reference types="cookie-session"/>
13+
export const foo = 1;
14+
>foo : Symbol(foo, Decl(index.d.ts, 1, 12))
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/processingDiagnosticSkipLibCheck.ts] ////
2+
3+
=== /index.ts ===
4+
import { foo } from 'foo';
5+
>foo : 1
6+
7+
const y = foo;
8+
>y : 1
9+
>foo : 1
10+
11+
=== /node_modules/foo/index.d.ts ===
12+
/// <reference types="cookie-session"/>
13+
export const foo = 1;
14+
>foo : 1
15+
>1 : 1
16+

testdata/baselines/reference/tsbuild/demo/in-bad-ref-branch-reports-the-error-about-files-not-in-rootDir-at-the-import-location.js

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ Output::
133133
4 import { createDog, Dog } from './dog';
134134
   ~~~~~~~
135135

136+
core/utilities.ts:1:13 - error TS6133: 'A' is declared but its value is never read.
137+
138+
1 import * as A from '../animals'
139+
   ~
140+
136141
core/utilities.ts:1:20 - error TS6307: File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.
137142
The file is in the program because:
138143
Imported via '../animals' from file '/user/username/projects/demo/core/utilities.ts'
@@ -154,11 +159,11 @@ Output::
154159
[HH:MM:SS AM] Building project 'zoo/tsconfig.json'...
155160

156161

157-
Found 3 errors in 2 files.
162+
Found 4 errors in 2 files.
158163

159164
Errors Files
160165
2 animals/index.ts:1
161-
1 core/utilities.ts[90m:1[0m
166+
2 core/utilities.ts[90m:1[0m
162167

163168
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
164169
/// <reference no-default-lib="true"/>
@@ -395,11 +400,10 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
395400
"size": 2794
396401
}
397402
//// [/user/username/projects/demo/lib/core/tsconfig.tsbuildinfo] *new*
398-
{"version":"FakeTSVersion","errors":true,"root":[5],"fileNames":["lib.d.ts","../../animals/animal.ts","../../animals/dog.ts","../../animals/index.ts","../../core/utilities.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\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":"47f086fff365b1e8b96a6df2c4313c1a-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}","signature":"1d76529d4652ddf9ebdfa65e748240fb-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}\n","impliedNodeFormat":1},{"version":"39dbb9b755eef022e56879989968e5cf-import Animal from '.';\nimport { makeRandomName } from '../core/utilities';\n\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\n\nexport function createDog(): Dog {\n return ({\n size: \"medium\",\n woof: function(this: Dog) {\n console.log(`${ this.name } says \"Woof\"!`);\n },\n name: makeRandomName()\n });\n}","signature":"4dc4bc559452869bfd0d92b5ed5d604f-import Animal from '.';\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\nexport declare function createDog(): Dog;\n","impliedNodeFormat":1},{"version":"d6a6b65b86b0330b1a1bd96b1738d5a4-import Animal from './animal';\n\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };","signature":"a3e41a5ccafc3d07a201f0603e28edcf-import Animal from './animal';\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };\n","impliedNodeFormat":1},{"version":"c71a99e072793c29cda49dd3fea04661-import * as A from '../animals'\nexport function makeRandomName() {\n return \"Bob!?! \";\n}\n\nexport function lastElementOf<T>(arr: T[]): T | undefined {\n if (arr.length === 0) return undefined;\n return arr[arr.length - 1];\n}","signature":"096c311e7aecdb577f7b613fbf1716e5-export declare function makeRandomName(): string;\nexport declare function lastElementOf<T>(arr: T[]): T | undefined;\n","impliedNodeFormat":1}],"fileIdsList":[[4,5],[2,3],[4]],"options":{"composite":true,"declaration":true,"module":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../../core","strict":true,"target":1},"referencedMap":[[3,1],[4,2],[5,3]],"semanticDiagnosticsPerFile":[1,2,3,4,5],"latestChangedDtsFile":"./utilities.d.ts"}
403+
{"version":"FakeTSVersion","root":[5],"fileNames":["lib.d.ts","../../animals/animal.ts","../../animals/dog.ts","../../animals/index.ts","../../core/utilities.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\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":"47f086fff365b1e8b96a6df2c4313c1a-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}","signature":"1d76529d4652ddf9ebdfa65e748240fb-export type Size = \"small\" | \"medium\" | \"large\";\nexport default interface Animal {\n size: Size;\n}\n","impliedNodeFormat":1},{"version":"39dbb9b755eef022e56879989968e5cf-import Animal from '.';\nimport { makeRandomName } from '../core/utilities';\n\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\n\nexport function createDog(): Dog {\n return ({\n size: \"medium\",\n woof: function(this: Dog) {\n console.log(`${ this.name } says \"Woof\"!`);\n },\n name: makeRandomName()\n });\n}","signature":"4dc4bc559452869bfd0d92b5ed5d604f-import Animal from '.';\nexport interface Dog extends Animal {\n woof(): void;\n name: string;\n}\nexport declare function createDog(): Dog;\n","impliedNodeFormat":1},{"version":"d6a6b65b86b0330b1a1bd96b1738d5a4-import Animal from './animal';\n\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };","signature":"a3e41a5ccafc3d07a201f0603e28edcf-import Animal from './animal';\nexport default Animal;\nimport { createDog, Dog } from './dog';\nexport { createDog, Dog };\n","impliedNodeFormat":1},{"version":"c71a99e072793c29cda49dd3fea04661-import * as A from '../animals'\nexport function makeRandomName() {\n return \"Bob!?! \";\n}\n\nexport function lastElementOf<T>(arr: T[]): T | undefined {\n if (arr.length === 0) return undefined;\n return arr[arr.length - 1];\n}","signature":"096c311e7aecdb577f7b613fbf1716e5-export declare function makeRandomName(): string;\nexport declare function lastElementOf<T>(arr: T[]): T | undefined;\n","impliedNodeFormat":1}],"fileIdsList":[[4,5],[2,3],[4]],"options":{"composite":true,"declaration":true,"module":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../../core","strict":true,"target":1},"referencedMap":[[3,1],[4,2],[5,3]],"semanticDiagnosticsPerFile":[[4,[{"pos":19,"end":29,"code":6307,"category":1,"message":"File '/user/username/projects/demo/animals/animal.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."},{"pos":86,"end":93,"code":6307,"category":1,"message":"File '/user/username/projects/demo/animals/dog.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."}]],[5,[{"pos":12,"end":13,"code":6133,"category":1,"message":"'A' is declared but its value is never read.","reportsUnnecessary":true},{"pos":19,"end":31,"code":6307,"category":1,"message":"File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.","messageChain":[{"noFile":true,"pos":-1,"end":-1,"code":1430,"category":3,"message":"The file is in the program because:","messageChain":[{"noFile":true,"pos":-1,"end":-1,"code":1393,"category":3,"message":"Imported via '../animals' from file '/user/username/projects/demo/core/utilities.ts'"},{"noFile":true,"pos":-1,"end":-1,"code":1393,"category":3,"message":"Imported via '.' from file '/user/username/projects/demo/animals/dog.ts'"}]}],"relatedInformation":[{"file":3,"pos":19,"end":22,"code":1399,"category":3,"message":"File is included via import here."}]}]]],"latestChangedDtsFile":"./utilities.d.ts"}
399404
//// [/user/username/projects/demo/lib/core/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
400405
{
401406
"version": "FakeTSVersion",
402-
"errors": true,
403407
"root": [
404408
{
405409
"files": [
@@ -513,14 +517,86 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
513517
]
514518
},
515519
"semanticDiagnosticsPerFile": [
516-
"lib.d.ts",
517-
"../../animals/animal.ts",
518-
"../../animals/dog.ts",
519-
"../../animals/index.ts",
520-
"../../core/utilities.ts"
520+
[
521+
"../../animals/index.ts",
522+
[
523+
{
524+
"pos": 19,
525+
"end": 29,
526+
"code": 6307,
527+
"category": 1,
528+
"message": "File '/user/username/projects/demo/animals/animal.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."
529+
},
530+
{
531+
"pos": 86,
532+
"end": 93,
533+
"code": 6307,
534+
"category": 1,
535+
"message": "File '/user/username/projects/demo/animals/dog.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern."
536+
}
537+
]
538+
],
539+
[
540+
"../../core/utilities.ts",
541+
[
542+
{
543+
"pos": 12,
544+
"end": 13,
545+
"code": 6133,
546+
"category": 1,
547+
"message": "'A' is declared but its value is never read.",
548+
"reportsUnnecessary": true
549+
},
550+
{
551+
"pos": 19,
552+
"end": 31,
553+
"code": 6307,
554+
"category": 1,
555+
"message": "File '/user/username/projects/demo/animals/index.ts' is not listed within the file list of project '/user/username/projects/demo/core/tsconfig.json'. Projects must list all files or use an 'include' pattern.",
556+
"messageChain": [
557+
{
558+
"noFile": true,
559+
"pos": -1,
560+
"end": -1,
561+
"code": 1430,
562+
"category": 3,
563+
"message": "The file is in the program because:",
564+
"messageChain": [
565+
{
566+
"noFile": true,
567+
"pos": -1,
568+
"end": -1,
569+
"code": 1393,
570+
"category": 3,
571+
"message": "Imported via '../animals' from file '/user/username/projects/demo/core/utilities.ts'"
572+
},
573+
{
574+
"noFile": true,
575+
"pos": -1,
576+
"end": -1,
577+
"code": 1393,
578+
"category": 3,
579+
"message": "Imported via '.' from file '/user/username/projects/demo/animals/dog.ts'"
580+
}
581+
]
582+
}
583+
],
584+
"relatedInformation": [
585+
{
586+
"file": "../../animals/dog.ts",
587+
"pos": 19,
588+
"end": 22,
589+
"code": 1399,
590+
"category": 3,
591+
"message": "File is included via import here."
592+
}
593+
]
594+
}
595+
]
596+
]
521597
],
522598
"latestChangedDtsFile": "./utilities.d.ts",
523-
"size": 3178
599+
"size": 4652
524600
}
525601
//// [/user/username/projects/demo/lib/core/utilities.d.ts] *new*
526602
export declare function makeRandomName(): string;
@@ -658,11 +734,11 @@ function createZoo() {
658734

659735
core/tsconfig.json::
660736
SemanticDiagnostics::
661-
*not cached* /home/src/tslibs/TS/Lib/lib.d.ts
662-
*not cached* /user/username/projects/demo/animals/animal.ts
663-
*not cached* /user/username/projects/demo/animals/dog.ts
664-
*not cached* /user/username/projects/demo/animals/index.ts
665-
*not cached* /user/username/projects/demo/core/utilities.ts
737+
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
738+
*refresh* /user/username/projects/demo/animals/animal.ts
739+
*refresh* /user/username/projects/demo/animals/dog.ts
740+
*refresh* /user/username/projects/demo/animals/index.ts
741+
*refresh* /user/username/projects/demo/core/utilities.ts
666742
Signatures::
667743
(stored at emit) /user/username/projects/demo/animals/animal.ts
668744
(stored at emit) /user/username/projects/demo/animals/dog.ts

0 commit comments

Comments
 (0)