Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic {
p.includeProcessor.getDiagnostics(p).GetGlobalDiagnostics()))
}

func (p *Program) GetIncludeProcessorDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
if checker.SkipTypeChecking(sourceFile, p.Options(), p, false) {
return nil
}
return p.includeProcessor.getDiagnostics(p).GetDiagnosticsForFile(sourceFile.FileName())
}

func (p *Program) getSourceFilesToEmit(targetSourceFile *ast.SourceFile, forceDtsEmit bool) []*ast.SourceFile {
if targetSourceFile == nil && !forceDtsEmit {
p.sourceFilesToEmitOnce.Do(func() {
Expand Down Expand Up @@ -1007,11 +1014,10 @@ func FilterNoEmitSemanticDiagnostics(diagnostics []*ast.Diagnostic, options *cor
}

func (p *Program) getSemanticDiagnosticsForFile(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic {
diagnostics := p.getSemanticDiagnosticsForFileNotFilter(ctx, sourceFile)
if diagnostics == nil {
return nil
}
return FilterNoEmitSemanticDiagnostics(diagnostics, p.Options())
return slices.Concat(
FilterNoEmitSemanticDiagnostics(p.getSemanticDiagnosticsForFileNotFilter(ctx, sourceFile), p.Options()),
p.GetIncludeProcessorDiagnostics(sourceFile),
)
}

func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic {
Expand All @@ -1026,8 +1032,7 @@ func (p *Program) getSemanticDiagnosticsForFileNotFilter(ctx context.Context, so
fileChecker, done = p.checkerPool.GetCheckerForFile(ctx, sourceFile)
defer done()
}
diags := slices.Clip(p.includeProcessor.getDiagnostics(p).GetDiagnosticsForFile(sourceFile.FileName()))
diags = append(diags, sourceFile.BindDiagnostics()...)
diags := slices.Clip(sourceFile.BindDiagnostics())
checkers, closeCheckers := p.checkerPool.GetAllCheckers(ctx)
defer closeCheckers()

Expand Down
30 changes: 19 additions & 11 deletions internal/execute/incremental/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,27 @@ func (p *Program) GetSemanticDiagnostics(ctx context.Context, file *ast.SourceFi

// Return result from cache
if file != nil {
cachedDiagnostics, ok := p.snapshot.semanticDiagnosticsPerFile.Load(file.Path())
if !ok {
panic("After handling all the affected files, there shouldnt be more changes")
}
return compiler.FilterNoEmitSemanticDiagnostics(cachedDiagnostics.getDiagnostics(p.program, file), p.snapshot.options)
return p.getSemanticDiagnosticsOfFile(file)
}

var diagnostics []*ast.Diagnostic
for _, file := range p.program.GetSourceFiles() {
cachedDiagnostics, ok := p.snapshot.semanticDiagnosticsPerFile.Load(file.Path())
if !ok {
panic("After handling all the affected files, there shouldnt be more changes")
}
diagnostics = append(diagnostics, compiler.FilterNoEmitSemanticDiagnostics(cachedDiagnostics.getDiagnostics(p.program, file), p.snapshot.options)...)
diagnostics = append(diagnostics, p.getSemanticDiagnosticsOfFile(file)...)
}
return diagnostics
}

func (p *Program) getSemanticDiagnosticsOfFile(file *ast.SourceFile) []*ast.Diagnostic {
cachedDiagnostics, ok := p.snapshot.semanticDiagnosticsPerFile.Load(file.Path())
if !ok {
panic("After handling all the affected files, there shouldnt be more changes")
}
return slices.Concat(
compiler.FilterNoEmitSemanticDiagnostics(cachedDiagnostics.getDiagnostics(p.program, file), p.snapshot.options),
p.program.GetIncludeProcessorDiagnostics(file),
)
}

// GetDeclarationDiagnostics implements compiler.AnyProgram interface.
func (p *Program) GetDeclarationDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic {
p.panicIfNoProgram("GetDeclarationDiagnostics")
Expand Down Expand Up @@ -298,11 +301,15 @@ func (p *Program) emitBuildInfo(ctx context.Context, options compiler.EmitOption
}

func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler.Program) {
var hasIncludeProcessingDiagnostics bool
if slices.ContainsFunc(program.GetSourceFiles(), func(file *ast.SourceFile) bool {
if _, ok := p.snapshot.emitDiagnosticsPerFile.Load(file.Path()); ok {
// emit diagnostics will be encoded in buildInfo;
return true
}
if !hasIncludeProcessingDiagnostics && len(p.program.GetIncludeProcessorDiagnostics(file)) > 0 {
hasIncludeProcessingDiagnostics = true
}
return false
}) {
// Record this for only non incremental build info
Expand All @@ -311,7 +318,8 @@ func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler
p.snapshot.hasSemanticErrors = false
return
}
if len(program.GetConfigFileParsingDiagnostics()) > 0 ||
if hasIncludeProcessingDiagnostics ||
len(program.GetConfigFileParsingDiagnostics()) > 0 ||
len(program.GetSyntacticDiagnostics(ctx, nil)) > 0 ||
len(program.GetProgramDiagnostics()) > 0 ||
len(program.GetBindDiagnostics(ctx, nil)) > 0 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,11 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
"size": 2794
}
//// [/user/username/projects/demo/lib/core/tsconfig.tsbuildinfo] *new*
{"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"}
{"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":[[5,[{"pos":12,"end":13,"code":6133,"category":1,"message":"'A' is declared but its value is never read.","reportsUnnecessary":true}]]],"latestChangedDtsFile":"./utilities.d.ts"}
//// [/user/username/projects/demo/lib/core/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"errors": true,
"root": [
{
"files": [
Expand Down Expand Up @@ -517,25 +518,6 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
]
},
"semanticDiagnosticsPerFile": [
[
"../../animals/index.ts",
[
{
"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."
}
]
],
[
"../../core/utilities.ts",
[
Expand All @@ -546,57 +528,12 @@ Object.defineProperty(exports, "createDog", { enumerable: true, get: function ()
"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": "../../animals/dog.ts",
"pos": 19,
"end": 22,
"code": 1399,
"category": 3,
"message": "File is included via import here."
}
]
}
]
]
],
"latestChangedDtsFile": "./utilities.d.ts",
"size": 4652
"size": 3302
}
//// [/user/username/projects/demo/lib/core/utilities.d.ts] *new*
export declare function makeRandomName(): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ const hello_json_1 = __importDefault(require("./hello.json"));
exports.default = hello_json_1.default.hello;

//// [/home/src/workspaces/solution/project/dist/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":[3],"fileNames":["lib.d.ts","../src/hello.json","../src/index.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":"18e7247c85a6a2e7a4ec2e284716edd8-{\n \"hello\": \"world\"\n}"},{"version":"c15eb6733af1bd811cd113368bb377e5-import hello from \"./hello.json\"\nexport default hello.hello","signature":"a44184f4ac1ed50126ac624c885b51a8-declare const _default: string;\nexport default _default;\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"allowSyntheticDefaultImports":true,"composite":true,"esModuleInterop":true,"module":1,"outDir":"./","skipDefaultLibCheck":true},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"pos":18,"end":32,"code":6307,"category":1,"message":"File '/home/src/workspaces/solution/project/src/hello.json' is not listed within the file list of project '/home/src/workspaces/solution/project/tsconfig.json'. Projects must list all files or use an 'include' pattern."}]]],"latestChangedDtsFile":"./src/index.d.ts"}
{"version":"FakeTSVersion","errors":true,"root":[3],"fileNames":["lib.d.ts","../src/hello.json","../src/index.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":"18e7247c85a6a2e7a4ec2e284716edd8-{\n \"hello\": \"world\"\n}"},{"version":"c15eb6733af1bd811cd113368bb377e5-import hello from \"./hello.json\"\nexport default hello.hello","signature":"a44184f4ac1ed50126ac624c885b51a8-declare const _default: string;\nexport default _default;\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"allowSyntheticDefaultImports":true,"composite":true,"esModuleInterop":true,"module":1,"outDir":"./","skipDefaultLibCheck":true},"referencedMap":[[3,1]],"latestChangedDtsFile":"./src/index.d.ts"}
//// [/home/src/workspaces/solution/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"errors": true,
"root": [
{
"files": [
Expand Down Expand Up @@ -163,22 +164,8 @@ exports.default = hello_json_1.default.hello;
"../src/hello.json"
]
},
"semanticDiagnosticsPerFile": [
[
"../src/index.ts",
[
{
"pos": 18,
"end": 32,
"code": 6307,
"category": 1,
"message": "File '/home/src/workspaces/solution/project/src/hello.json' is not listed within the file list of project '/home/src/workspaces/solution/project/tsconfig.json'. Projects must list all files or use an 'include' pattern."
}
]
]
],
"latestChangedDtsFile": "./src/index.d.ts",
"size": 1741
"size": 1442
}

project/tsconfig.json::
Expand Down
Loading
Loading