diff --git a/internal/api/proto.go b/internal/api/proto.go index bc4595fde8..68da823633 100644 --- a/internal/api/proto.go +++ b/internal/api/proto.go @@ -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, } } diff --git a/internal/api/proto_test.go b/internal/api/proto_test.go index 6ed8625e12..44bac19334 100644 --- a/internal/api/proto_test.go +++ b/internal/api/proto_test.go @@ -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" ) @@ -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) +}