Skip to content

Decouple snapshot ownership from project.Session so api.Session only uses one in LSP mode - #64163

Open
Andrew Branch (andrewbranch) wants to merge 5 commits into
microsoft:mainfrom
andrewbranch:copilot/snapshot-store-refactor
Open

Decouple snapshot ownership from project.Session so api.Session only uses one in LSP mode#64163
Andrew Branch (andrewbranch) wants to merge 5 commits into
microsoft:mainfrom
andrewbranch:copilot/snapshot-store-refactor

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

This is a refactor that will make #64154 cleaner. A project.Session owns a canonical/latest snapshot, which makes sense as the state backing an LSP server. But that will make it awkward to use in the standalone API when we want to remove the concept of a singular latest snapshot.¹ This moves the infrastructure necessary to clone a snapshot (mostly caches) into a project.SnapshotHost (open to naming suggestions) so api.Session can deal with that for most of its operations, while in LSP mode, the methods that can actually affect LSP state still go through project.Session, so they're very easy to identify.

¹ This doesn't yet remove the single-latest-snapshot concept from the API, as I think that will necessarily change how things look all the way down to the client, and I wanted to take the opportunity to extract this as a scoped refactor.

Copilot AI balanced review requested due to automatic review settings September 4, 2026 02:36
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 4, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Async connection shutdown can wait indefinitely for handlers whose context remains live after EOF.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Decouples snapshot ownership from project.Session, enabling standalone API sessions to manage snapshots directly while LSP sessions retain canonical state.

Changes:

  • Introduces SnapshotStore for snapshot creation, caches, IDs, and disposal.
  • Splits API construction into standalone and LSP-backed sessions.
  • Tracks asynchronous IPC handlers during connection shutdown.
File summaries
File Description
tsc/internal/project/snapshotstore.go Adds shared snapshot infrastructure.
tsc/internal/project/snapshot.go Moves snapshot dependencies to SnapshotStore.
tsc/internal/project/snapshot_test.go Updates snapshot adoption test.
tsc/internal/project/session.go Delegates snapshot ownership to the store.
tsc/internal/project/refcountcache_test.go Updates cache ownership references.
tsc/internal/project/extendedconfigcache_test.go Updates extended-config cache references.
tsc/internal/project/api.go Exposes background snapshot adoption.
tsc/internal/lsp/server.go Creates LSP-backed API sessions.
tsc/internal/ipc/conn_async.go Waits for asynchronous handlers on shutdown.
tsc/internal/ipc/conn_async_test.go Tests handler waiting behavior.
tsc/internal/api/session.go Supports standalone and LSP snapshot stores.
tsc/internal/api/session_temporary_test.go Uses the LSP session constructor.
tsc/internal/api/session_createprogram_test.go Updates and expands program tests.
tsc/internal/api/session_completion_test.go Uses the LSP session constructor.
tsc/internal/api/session_apistate_test.go Adds standalone-session coverage.
tsc/internal/api/server.go Removes standalone project.Session creation.
Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/ipc/conn_async.go
Comment on lines +385 to +388
// compatibilitySnapshot is the standalone API session's canonical snapshot.
// It preserves the legacy linear updateSnapshot behavior.
compatibilitySnapshot *project.Snapshot
compatibilityMu sync.Mutex

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is now the standalone API’s “latest snapshot” instead of using s.projectSession.Snapshot(), and will be removed in a subsequent PR.

defer func() { c.closePendingCalls(err) }()
defer func() {
c.closePendingCalls(err)
c.handlers.Wait()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Drive-by fix

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

project.Session.Close currently recurses indefinitely, and one changed line also fails gofmt.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread tsc/internal/project/session.go Outdated
Comment thread tsc/internal/project/session.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Direct host cloning drops the LSP client and can reuse content-mapped diagnostics under the wrong locale.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 1
  • Review effort level: Balanced

// ataChanges contains ATA-related changes to apply to projects in the new snapshot.
ataChanges map[tspath.Path]*ATAStateChange
apiRequest *APISnapshotRequest
client Client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants