|
6 | 6 | "testing"
|
7 | 7 |
|
8 | 8 | "github.com/microsoft/typescript-go/internal/bundled"
|
| 9 | + "github.com/microsoft/typescript-go/internal/core" |
| 10 | + "github.com/microsoft/typescript-go/internal/glob" |
9 | 11 | "github.com/microsoft/typescript-go/internal/lsp/lsproto"
|
10 | 12 | "github.com/microsoft/typescript-go/internal/testutil/projecttestutil"
|
11 | 13 | "github.com/microsoft/typescript-go/internal/tspath"
|
@@ -548,6 +550,55 @@ func TestSession(t *testing.T) {
|
548 | 550 | assert.Check(t, lsAfter.GetProgram() != programBefore)
|
549 | 551 | })
|
550 | 552 |
|
| 553 | + t.Run("change program file not in tsconfig root files", func(t *testing.T) { |
| 554 | + t.Parallel() |
| 555 | + files := map[string]any{ |
| 556 | + "/home/projects/TS/p1/tsconfig.json": `{ |
| 557 | + "compilerOptions": { |
| 558 | + "noLib": true, |
| 559 | + "module": "nodenext", |
| 560 | + "strict": true |
| 561 | + }, |
| 562 | + "files": ["src/index.ts"] |
| 563 | + }`, |
| 564 | + "/home/projects/TS/p1/src/index.ts": `import { x } from "../../x";`, |
| 565 | + "/home/projects/TS/x.ts": `export const x = 1;`, |
| 566 | + } |
| 567 | + |
| 568 | + session, utils := projecttestutil.Setup(files) |
| 569 | + session.DidOpenFile(context.Background(), "file:///home/projects/TS/p1/src/index.ts", 1, files["/home/projects/TS/p1/src/index.ts"].(string), lsproto.LanguageKindTypeScript) |
| 570 | + lsBefore, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/src/index.ts") |
| 571 | + assert.NilError(t, err) |
| 572 | + programBefore := lsBefore.GetProgram() |
| 573 | + session.WaitForBackgroundTasks() |
| 574 | + |
| 575 | + var xWatched bool |
| 576 | + outer: |
| 577 | + for _, call := range utils.Client().WatchFilesCalls() { |
| 578 | + for _, watcher := range call.Watchers { |
| 579 | + if core.Must(glob.Parse(*watcher.GlobPattern.Pattern)).Match("/home/projects/TS/x.ts") { |
| 580 | + xWatched = true |
| 581 | + break outer |
| 582 | + } |
| 583 | + } |
| 584 | + } |
| 585 | + assert.Check(t, xWatched) |
| 586 | + |
| 587 | + err = utils.FS().WriteFile("/home/projects/TS/x.ts", `export const x = 2;`, false) |
| 588 | + assert.NilError(t, err) |
| 589 | + |
| 590 | + session.DidChangeWatchedFiles(context.Background(), []*lsproto.FileEvent{ |
| 591 | + { |
| 592 | + Type: lsproto.FileChangeTypeChanged, |
| 593 | + Uri: "file:///home/projects/TS/x.ts", |
| 594 | + }, |
| 595 | + }) |
| 596 | + |
| 597 | + lsAfter, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/src/index.ts") |
| 598 | + assert.NilError(t, err) |
| 599 | + assert.Check(t, lsAfter.GetProgram() != programBefore) |
| 600 | + }) |
| 601 | + |
551 | 602 | t.Run("change config file", func(t *testing.T) {
|
552 | 603 | t.Parallel()
|
553 | 604 | files := map[string]any{
|
|
0 commit comments