Skip to content

Handle unloaded projects in API snapshot responses#4483

Open
ulitink wants to merge 2 commits into
microsoft:mainfrom
JetBrains:ulitin/handle-unloaded-projects-in-snapshot-responses
Open

Handle unloaded projects in API snapshot responses#4483
ulitink wants to merge 2 commits into
microsoft:mainfrom
JetBrains:ulitin/handle-unloaded-projects-in-snapshot-responses

Conversation

@ulitink

@ulitink ulitink commented Jun 30, 2026

Copy link
Copy Markdown

Opening a file can load its nearest configured project while solution search discovers an ancestor tsconfig as an unloaded placeholder. API updateSnapshot previously serialized every project assuming CommandLine was non-nil, which couldp anic for that unloaded ancestor project.

Error: panic: runtime error: invalid memory address or nil pointer dereference
goroutine 932 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/api.(*AsyncConn).handleRequest.func1()
	github.com/microsoft/typescript-go/internal/api/conn_async.go:96 +0x58
panic({0xdd6c80?, 0x1b43150?})
	runtime/panic.go:860 +0x13a
github.com/microsoft/typescript-go/internal/tsoptions.(*ParsedCommandLine).FileNames(...)
	github.com/microsoft/typescript-go/internal/tsoptions/parsedcommandline.go:295
github.com/microsoft/typescript-go/internal/api.NewProjectResponse(...)
	github.com/microsoft/typescript-go/internal/api/proto.go:500
github.com/microsoft/typescript-go/internal/api.(*Session).handleUpdateSnapshot(0x18b1c3e22230, {0x11cec30, 0x18b1c3f85950}, 0x18b1bd2e5dc0)
	github.com/microsoft/typescript-go/internal/api/session.go:913 +0x1401
github.com/microsoft/typescript-go/internal/api.(*Session).HandleRequest(0x18b1c3e22230, {0x11cec30, 0x18b1c3f85950}, {0x18b1bc646902, 0xe}, {0x18b1b97a2980?, 0x18b1bbdca708?, 0x18b1c1549790?})
	github.com/microsoft/typescript-go/internal/api/session.go:521 +0xbe9
github.com/microsoft/typescript-go/internal/api.(*AsyncConn).handleRequest(0x18b1c3f859a0, {0x11cec30?, 0x18b1c3f85950?}, 0x18b1c35761e0)
	github.com/microsoft/typescript-go/internal/api/conn_async.go:112 +0xb4
created by github.com/microsoft/typescript-go/internal/api.(*AsyncConn).Run in goroutine 899
	github.com/microsoft/typescript-go/internal/api/conn_async.go:66 +0x105

Copilot AI review requested due to automatic review settings June 30, 2026 10:23
@ulitink

ulitink commented Jun 30, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="JetBrains"

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.

Pull request overview

This PR addresses a panic in the API updateSnapshot response serialization path when a snapshot contains an “unloaded” configured project whose CommandLine is nil (e.g., an ancestor tsconfig discovered during solution search).

Changes:

  • Add a regression test covering serialization of a snapshot that includes both a loaded nested configured project and an unloaded ancestor configured project.
  • Update NewProjectResponse to avoid dereferencing p.CommandLine when it is nil.

Reviewed changes

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

File Description
internal/api/proto.go Adds a nil guard in NewProjectResponse to prevent panics when serializing projects without a command line.
internal/api/session_apistate_test.go Adds a regression test that exercises updateSnapshot when an unloaded ancestor configured project is present.

Comment thread internal/api/proto.go
Comment thread internal/api/session_apistate_test.go Outdated

@andrewbranch andrewbranch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we just filter these stub projects out of the API response instead?

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.

3 participants