Skip to content

Update snapshot and projects on file close#3837

Merged
gabritto merged 8 commits into
mainfrom
gabritto/issue3676pt2
May 15, 2026
Merged

Update snapshot and projects on file close#3837
gabritto merged 8 commits into
mainfrom
gabritto/issue3676pt2

Conversation

@gabritto
Copy link
Copy Markdown
Member

Fixes #3676.
We were missing a couple things to make this scenario work:

  • Update snapshots on didClose so that we don't wait until a request comes in to clean up tsconfig diagnostics
  • Clean up closed projects on file close during project collection build.

Note 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).

@gabritto gabritto requested a review from Copilot May 13, 2026 23:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ScheduleSnapshotUpdate mechanism (mirroring ScheduleDiagnosticsRefresh) and invoke it from DidCloseFile to flush pending close events after a short delay.
  • Extended ProjectCollectionBuilder.DidChangeFiles to 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.

@gabritto gabritto marked this pull request as ready for review May 14, 2026 15:21
@gabritto gabritto requested a review from andrewbranch May 14, 2026 15:21
@andrewbranch
Copy link
Copy Markdown
Member

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?

@gabritto
Copy link
Copy Markdown
Member Author

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. 🙁

@gabritto gabritto requested a review from Copilot May 14, 2026 20:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread internal/project/session.go Outdated
Comment thread internal/project/session.go
Comment thread internal/project/session.go
@gabritto gabritto requested a review from Copilot May 15, 2026 19:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread internal/project/session.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@gabritto gabritto added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit a7acc87 May 15, 2026
25 checks passed
@gabritto gabritto deleted the gabritto/issue3676pt2 branch May 15, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsconfig diagnostics not refreshed if no TS/JS files are open

3 participants