|
7 | 7 |
|
8 | 8 | "github.com/microsoft/TypeScript/tsc/internal/ast" |
9 | 9 | "github.com/microsoft/TypeScript/tsc/internal/bundled" |
| 10 | + "github.com/microsoft/TypeScript/tsc/internal/collections" |
10 | 11 | "github.com/microsoft/TypeScript/tsc/internal/compiler" |
11 | 12 | "github.com/microsoft/TypeScript/tsc/internal/contentmapper" |
12 | 13 | "github.com/microsoft/TypeScript/tsc/internal/core" |
@@ -491,5 +492,81 @@ func TestRefCountingCaches(t *testing.T) { |
491 | 492 | _, ok = session.extendedConfigCache.entries.Load(extendedConfigPath) |
492 | 493 | assert.Assert(t, !ok) |
493 | 494 | }) |
| 495 | + |
| 496 | + t.Run("createProgram retains and reloads extended configs from referenced projects", func(t *testing.T) { |
| 497 | + t.Parallel() |
| 498 | + |
| 499 | + const ( |
| 500 | + appConfigPath = "/user/username/projects/app/tsconfig.json" |
| 501 | + appFilePath = "/user/username/projects/app/index.ts" |
| 502 | + libConfigPath = "/user/username/projects/lib/tsconfig.json" |
| 503 | + libBaseConfigPath = "/user/username/projects/lib/tsconfig.base.json" |
| 504 | + libFilePath = "/user/username/projects/lib/index.ts" |
| 505 | + ) |
| 506 | + session := setup(map[string]any{ |
| 507 | + appConfigPath: `{"compilerOptions":{"noLib":true},"files":["index.ts"],"references":[{"path":"../lib"}]}`, |
| 508 | + appFilePath: "export const app = 1;", |
| 509 | + libConfigPath: `{"extends":"./tsconfig.base.json","files":["index.ts"]}`, |
| 510 | + libBaseConfigPath: `{"compilerOptions":{"composite":true,"noLib":true}}`, |
| 511 | + libFilePath: "export const lib = 1;", |
| 512 | + }) |
| 513 | + defer session.Close() |
| 514 | + ctx := context.Background() |
| 515 | + |
| 516 | + baseSnapshot, err := session.APIUpdate(ctx, FileChangeSummary{}, &APISnapshotRequest{ |
| 517 | + OpenProjects: collections.NewSetFromItems(appConfigPath), |
| 518 | + }) |
| 519 | + assert.NilError(t, err) |
| 520 | + defer baseSnapshot.Deref(session) |
| 521 | + appProject := baseSnapshot.ProjectCollection.GetProjectByPath(baseSnapshot.toPath(appConfigPath)) |
| 522 | + assert.Assert(t, appProject != nil) |
| 523 | + |
| 524 | + programSnapshot := session.APICreateProgram( |
| 525 | + ctx, |
| 526 | + appProject.CommandLine.FileNames(), |
| 527 | + appProject.CommandLine.CompilerOptions(), |
| 528 | + appProject.CommandLine.ProjectReferences(), |
| 529 | + appProject.CommandLine.Errors, |
| 530 | + baseSnapshot, |
| 531 | + appProject, |
| 532 | + FileChangeSummary{}, |
| 533 | + ) |
| 534 | + defer programSnapshot.Deref(session) |
| 535 | + programProject := programSnapshot.ProjectCollection.InferredProject() |
| 536 | + assert.Assert(t, programProject != nil) |
| 537 | + assert.Assert(t, programProject.Program == appProject.Program) |
| 538 | + |
| 539 | + extendedConfigEntry, ok := session.extendedConfigCache.entries.Load(tspath.Path(libBaseConfigPath)) |
| 540 | + assert.Assert(t, ok) |
| 541 | + extendedConfigEntry.mu.Lock() |
| 542 | + _, ownedByBaseSnapshot := extendedConfigEntry.owners[baseSnapshot.id] |
| 543 | + _, ownedByProgramSnapshot := extendedConfigEntry.owners[programSnapshot.id] |
| 544 | + ownerCount := len(extendedConfigEntry.owners) |
| 545 | + extendedConfigEntry.mu.Unlock() |
| 546 | + assert.Assert(t, ownedByBaseSnapshot) |
| 547 | + assert.Assert(t, ownedByProgramSnapshot) |
| 548 | + assert.Equal(t, ownerCount, 2) |
| 549 | + |
| 550 | + assert.NilError(t, session.fs.fs.WriteFile(libBaseConfigPath, `{"compilerOptions":{"composite":true,"noLib":true,"strict":true}}`)) |
| 551 | + var fileChanges FileChangeSummary |
| 552 | + fileChanges.Changed.Add(lsproto.DocumentUri("file://" + libBaseConfigPath)) |
| 553 | + updatedProgramSnapshot := session.APICreateProgram( |
| 554 | + ctx, |
| 555 | + programProject.CommandLine.FileNames(), |
| 556 | + programProject.CommandLine.CompilerOptions(), |
| 557 | + programProject.CommandLine.ProjectReferences(), |
| 558 | + programProject.CommandLine.Errors, |
| 559 | + programSnapshot, |
| 560 | + programProject, |
| 561 | + fileChanges, |
| 562 | + ) |
| 563 | + defer updatedProgramSnapshot.Deref(session) |
| 564 | + updatedProgramProject := updatedProgramSnapshot.ProjectCollection.InferredProject() |
| 565 | + assert.Assert(t, updatedProgramProject != nil) |
| 566 | + assert.Assert(t, updatedProgramProject.Program != programProject.Program) |
| 567 | + updatedReferences := updatedProgramProject.Program.GetResolvedProjectReferences() |
| 568 | + assert.Equal(t, len(updatedReferences), 1) |
| 569 | + assert.Equal(t, updatedReferences[0].CompilerOptions().Strict, core.TSTrue) |
| 570 | + }) |
494 | 571 | }) |
495 | 572 | } |
0 commit comments