Update snapshot and projects on file close#3837
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes #3676 by ensuring tsconfig diagnostics are refreshed after the last TS/JS file in a project is closed. Previously, snapshot updates (and project cleanup) were deferred until the next request arrived, leaving stale tsconfig diagnostics displayed to the user.
Changes:
- Added a debounced
ScheduleSnapshotUpdatemechanism (mirroringScheduleDiagnosticsRefresh) and invoke it fromDidCloseFileto flush pending close events after a short delay. - Extended
ProjectCollectionBuilder.DidChangeFilesto also run the open/closed-file project retention pass when only files have been closed, so abandoned configured projects are deleted. - Cancel any scheduled snapshot update from all paths that take
snapshotUpdateMu(DidOpen, getSnapshot, idle cache clean, API entry points, Session.Close).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/project/session.go | Adds UpdateReasonDidCloseFile, ScheduleSnapshotUpdate/cancelScheduledSnapshotUpdate, and wires DidCloseFile to schedule a debounced update; cancels scheduled updates from other update paths and Close. |
| internal/project/snapshot.go | Adds logging for the new UpdateReasonDidCloseFile reason. |
| internal/project/projectcollectionbuilder.go | Runs the open/close project-retention loop when files are closed (not just opened) so closed projects are removed. |
| internal/project/api.go | Cancels any scheduled snapshot update on API open/update entry points. |
| internal/project/project_test.go | Adds publishDiagnosticsCall helper and a regression test verifying tsconfig diagnostics are cleared after the last TS file is closed. |
|
I know in Strada, we intentionally don't close projects on file close, because it would be wasteful if the next action you took was to open another file in the same project... but presumably, tsconfig diagnostics also work basically the way we want in Strada. How does that work? |
Apparently we don't clean up config diagnostics on project close in Strada. 🙁 |
…oject when publishing program diagnostics
…eep track of open/closed project changes
Fixes #3676.
We were missing a couple things to make this scenario work:
didCloseso that we don't wait until a request comes in to clean up tsconfig diagnosticsNote we'll always clean up tsconfig diagnostics once all files in that project are closed, even if the tsconfig.json remains open. We may want to have the server handle .json files in the future (though we'd still have push diagnostics, but only for global diagnostics and not diagnostics specific to the tsconfig itself).