Skip to content

Commit 463a747

Browse files
gabrittoGabriela Araujo Britto
andauthored
Don't cancel refresh except on file change (#3595)
Co-authored-by: Gabriela Araujo Britto <gabrielaa@CPC-gabri-8SHBT.localdomain>
1 parent 78b1ba1 commit 463a747

2 files changed

Lines changed: 88 additions & 3 deletions

File tree

internal/project/session.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ func (s *Session) InitializeWithUserConfig(config lsutil.UserPreferences) {
277277
}
278278

279279
func (s *Session) DidOpenFile(ctx context.Context, uri lsproto.DocumentUri, version int32, content string, languageKind lsproto.LanguageKind) {
280-
s.cancelDiagnosticsRefresh()
281280
s.cancelWarmAutoImportCache()
282281
s.scheduleIdleCacheClean()
283282
s.snapshotUpdateMu.Lock()
@@ -302,7 +301,6 @@ func (s *Session) DidOpenFile(ctx context.Context, uri lsproto.DocumentUri, vers
302301
}
303302

304303
func (s *Session) DidCloseFile(ctx context.Context, uri lsproto.DocumentUri) {
305-
s.cancelDiagnosticsRefresh()
306304
s.cancelWarmAutoImportCache()
307305
s.scheduleIdleCacheClean()
308306
s.pendingFileChangesMu.Lock()
@@ -328,7 +326,6 @@ func (s *Session) DidChangeFile(ctx context.Context, uri lsproto.DocumentUri, ve
328326
}
329327

330328
func (s *Session) DidSaveFile(ctx context.Context, uri lsproto.DocumentUri) {
331-
s.cancelDiagnosticsRefresh()
332329
s.scheduleIdleCacheClean()
333330
s.pendingFileChangesMu.Lock()
334331
defer s.pendingFileChangesMu.Unlock()

internal/project/session_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,94 @@ func TestSession(t *testing.T) {
910910
assert.Equal(t, len(program.GetSemanticDiagnostics(projecttestutil.WithRequestID(t.Context()), program.GetSourceFile("/home/projects/TS/p1/src/index.ts"))), 1)
911911
})
912912

913+
t.Run("delete sibling folder schedules diagnostics refresh", func(t *testing.T) {
914+
t.Parallel()
915+
files := map[string]any{
916+
"/home/projects/TS/p1/tsconfig.json": `{
917+
"compilerOptions": {
918+
"noLib": true
919+
},
920+
"files": ["index.ts"]
921+
}`,
922+
"/home/projects/TS/p1/index.ts": `import { content } from "./f/content";
923+
924+
export const value = content;`,
925+
"/home/projects/TS/p1/f/content.ts": `export const content = 1;`,
926+
}
927+
session, utils := projecttestutil.Setup(files)
928+
contentURI := lsproto.DocumentUri("file:///home/projects/TS/p1/f/content.ts")
929+
session.DidOpenFile(context.Background(), "file:///home/projects/TS/p1/index.ts", 1, files["/home/projects/TS/p1/index.ts"].(string), lsproto.LanguageKindTypeScript)
930+
session.DidOpenFile(context.Background(), contentURI, 1, files["/home/projects/TS/p1/f/content.ts"].(string), lsproto.LanguageKindTypeScript)
931+
932+
_, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/index.ts")
933+
assert.NilError(t, err)
934+
session.WaitForBackgroundTasks()
935+
936+
baselineRefreshCount := len(utils.Client().RefreshDiagnosticsCalls())
937+
938+
err = utils.FS().Remove("/home/projects/TS/p1/f")
939+
assert.NilError(t, err)
940+
941+
session.DidChangeWatchedFiles(context.Background(), []*lsproto.FileEvent{
942+
{
943+
Type: lsproto.FileChangeTypeDeleted,
944+
Uri: "file:///home/projects/TS/p1/f",
945+
},
946+
})
947+
session.DidCloseFile(context.Background(), contentURI)
948+
session.WaitForBackgroundTasks()
949+
950+
refreshCount := len(utils.Client().RefreshDiagnosticsCalls())
951+
assert.Assert(t, refreshCount > baselineRefreshCount,
952+
"expected RefreshDiagnostics to be called after deleting /home/projects/TS/p1/f, got %d calls (baseline %d)",
953+
refreshCount, baselineRefreshCount)
954+
})
955+
956+
t.Run("delete sibling folder schedules diagnostics refresh after opening third file", func(t *testing.T) {
957+
t.Parallel()
958+
files := map[string]any{
959+
"/home/projects/TS/p1/tsconfig.json": `{
960+
"compilerOptions": {
961+
"noLib": true
962+
},
963+
"files": ["index.ts", "third.ts"]
964+
}`,
965+
"/home/projects/TS/p1/index.ts": `import { content } from "./f/content";
966+
967+
export const value = content;`,
968+
"/home/projects/TS/p1/f/content.ts": `export const content = 1;`,
969+
"/home/projects/TS/p1/third.ts": `export const third = 3;`,
970+
}
971+
session, utils := projecttestutil.Setup(files)
972+
contentURI := lsproto.DocumentUri("file:///home/projects/TS/p1/f/content.ts")
973+
thirdURI := lsproto.DocumentUri("file:///home/projects/TS/p1/third.ts")
974+
session.DidOpenFile(context.Background(), "file:///home/projects/TS/p1/index.ts", 1, files["/home/projects/TS/p1/index.ts"].(string), lsproto.LanguageKindTypeScript)
975+
session.DidOpenFile(context.Background(), contentURI, 1, files["/home/projects/TS/p1/f/content.ts"].(string), lsproto.LanguageKindTypeScript)
976+
977+
_, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/index.ts")
978+
assert.NilError(t, err)
979+
session.WaitForBackgroundTasks()
980+
981+
baselineRefreshCount := len(utils.Client().RefreshDiagnosticsCalls())
982+
983+
err = utils.FS().Remove("/home/projects/TS/p1/f")
984+
assert.NilError(t, err)
985+
986+
session.DidChangeWatchedFiles(context.Background(), []*lsproto.FileEvent{
987+
{
988+
Type: lsproto.FileChangeTypeDeleted,
989+
Uri: "file:///home/projects/TS/p1/f",
990+
},
991+
})
992+
session.DidOpenFile(context.Background(), thirdURI, 1, files["/home/projects/TS/p1/third.ts"].(string), lsproto.LanguageKindTypeScript)
993+
session.WaitForBackgroundTasks()
994+
995+
refreshCount := len(utils.Client().RefreshDiagnosticsCalls())
996+
assert.Assert(t, refreshCount > baselineRefreshCount,
997+
"expected RefreshDiagnostics to be called after deleting /home/projects/TS/p1/f and opening /home/projects/TS/p1/third.ts, got %d calls (baseline %d)",
998+
refreshCount, baselineRefreshCount)
999+
})
1000+
9131001
t.Run("create explicitly included file", func(t *testing.T) {
9141002
t.Parallel()
9151003
files := map[string]any{

0 commit comments

Comments
 (0)