Skip to content
Open
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
26 changes: 26 additions & 0 deletions tsc/internal/project/contentmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,32 @@ func TestContentMapperInProject(t *testing.T) {
assert.Assert(t, strings.Contains(updated.Text(), "export const watched = true;"), "updated app.box missing watched change: %q", updated.Text())
})

t.Run("watch change to a content-mapped file schedules diagnostics refresh", func(t *testing.T) {
t.Parallel()
session, utils := newSession(true)
defer session.Close()

ctx := context.Background()
mainURI := lsproto.DocumentUri("file:///home/project/main.ts")
session.DidOpenFile(ctx, mainURI, 1, files["/home/project/main.ts"].(string), lsproto.LanguageKindTypeScript)
_, err := session.GetLanguageService(ctx, mainURI)
assert.NilError(t, err)
session.WaitForBackgroundTasks()

baselineRefreshCount := len(utils.Client().RefreshDiagnosticsCalls())
assert.NilError(t, utils.FS().WriteFile("/home/project/app.box", "export const version = #{target};\nexport const watched = true;\n"))
session.DidChangeWatchedFiles(ctx, []*lsproto.FileEvent{{
Uri: "file:///home/project/app.box",
Type: lsproto.FileChangeTypeChanged,
}})
session.WaitForBackgroundTasks()

refreshCount := len(utils.Client().RefreshDiagnosticsCalls())
assert.Assert(t, refreshCount > baselineRefreshCount,
"expected RefreshDiagnostics to be called after app.box changed on disk, got %d calls (baseline %d)",
refreshCount, baselineRefreshCount)
})

t.Run("unchanged content-mapped file is reused from the cache across a full rebuild", func(t *testing.T) {
t.Parallel()
session, utils := newSession(true)
Expand Down
7 changes: 2 additions & 5 deletions tsc/internal/project/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (s *Session) DidChangeWatchedFiles(ctx context.Context, changes []*lsproto.
if !hasRelevantChange {
filePath := change.Uri.Path()
path := s.caseSensitivity.PathKey(filePath).RemoveTrailingDirectorySeparator()
if contentMapperWatchedFiles.Has(path) {
if contentMapperWatchedFiles.Has(path) || path.ExtensionIsOneOf(contentMapperExtensions) {
hasRelevantChange = true
continue
}
Expand All @@ -468,10 +468,7 @@ func (s *Session) DidChangeWatchedFiles(ctx context.Context, changes []*lsproto.
}
}
} else {
if isRelevantExtension(extension) ||
path.ExtensionIsOneOf(contentMapperExtensions) {
hasRelevantChange = true
}
hasRelevantChange = true
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions tsc/internal/project/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,44 @@ export const value = content;`,
refreshCount, baselineRefreshCount)
})

t.Run("change to a declaration file schedules diagnostics refresh", func(t *testing.T) {
t.Parallel()
files := map[string]any{
"/home/projects/TS/p1/tsconfig.json": `{
"compilerOptions": {
"noLib": true
},
"files": ["index.ts", "types.d.ts"]
}`,
"/home/projects/TS/p1/index.ts": `export const value: Value = 1;`,
"/home/projects/TS/p1/types.d.ts": `type Value = string;`,
}
session, utils := projecttestutil.Setup(files)
session.DidOpenFile(context.Background(), "file:///home/projects/TS/p1/index.ts", 1, files["/home/projects/TS/p1/index.ts"].(string), lsproto.LanguageKindTypeScript)

_, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/index.ts")
assert.NilError(t, err)
session.WaitForBackgroundTasks()

baselineRefreshCount := len(utils.Client().RefreshDiagnosticsCalls())

err = utils.FS().WriteFile("/home/projects/TS/p1/types.d.ts", `type Value = number;`)
assert.NilError(t, err)

session.DidChangeWatchedFiles(context.Background(), []*lsproto.FileEvent{
{
Type: lsproto.FileChangeTypeChanged,
Uri: "file:///home/projects/TS/p1/types.d.ts",
},
})
session.WaitForBackgroundTasks()

refreshCount := len(utils.Client().RefreshDiagnosticsCalls())
assert.Assert(t, refreshCount > baselineRefreshCount,
"expected RefreshDiagnostics to be called after changing /home/projects/TS/p1/types.d.ts, got %d calls (baseline %d)",
refreshCount, baselineRefreshCount)
})

t.Run("delete sibling folder schedules diagnostics refresh after opening third file", func(t *testing.T) {
t.Parallel()
files := map[string]any{
Expand Down