Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/api/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,17 @@ type ProjectResponse struct {
}

func NewProjectResponse(p *project.Project) *ProjectResponse {
rootFiles := []string{}
var opts *core.CompilerOptions
if p.CommandLine != nil {
rootFiles = p.CommandLine.FileNames()
opts = p.CommandLine.CompilerOptions()
}
return &ProjectResponse{
Id: ProjectHandle(p),
ConfigFileName: p.Name(),
RootFiles: p.CommandLine.FileNames(),
CompilerOptions: p.CommandLine.CompilerOptions(),
RootFiles: rootFiles,
CompilerOptions: opts,
}
Comment on lines 395 to 407
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This fixes a panic path (nil CommandLine) but there’s no regression test to prevent it from coming back. Consider adding a small API/proto test that creates a project via project.Session.APIOpenProject, sets proj.CommandLine = nil, and asserts NewProjectResponse doesn’t panic (and that the JSON shape matches the TS API contract).

Copilot generated this review using guidance from repository custom instructions.
}

Expand Down
10 changes: 10 additions & 0 deletions internal/api/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/microsoft/typescript-go/internal/api"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/project"
"gotest.tools/v3/assert"
)

Expand Down Expand Up @@ -58,3 +59,12 @@ func TestDocumentIdentifierUnmarshalJSON(t *testing.T) {
})
}
}

func TestNewProjectResponse_NilCommandLine(t *testing.T) {
t.Parallel()
p := &project.Project{}
resp := api.NewProjectResponse(p)
assert.Assert(t, resp != nil)
assert.DeepEqual(t, resp.RootFiles, []string{})
assert.Assert(t, resp.CompilerOptions == nil)
}
Loading