Skip to content

fix: make ResponseMessage.Result omitzero #1533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 8, 2025
Merged
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
12 changes: 9 additions & 3 deletions internal/lsp/lsproto/_generate/generate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,16 @@ function generateCode() {
}

writeLine(`// Response type for \`${request.method}\``);
const resultType = resolveType(request.result);
const goType = resultType.needsPointer ? `*${resultType.name}` : resultType.name;

writeLine(`type ${responseTypeName} = ${goType}`);
// Special case for response types that are explicitly base type "null"
if (request.result.kind === "base" && request.result.name === "null") {
writeLine(`type ${responseTypeName} = Null`);
}
else {
const resultType = resolveType(request.result);
const goType = resultType.needsPointer ? `*${resultType.name}` : resultType.name;
writeLine(`type ${responseTypeName} = ${goType}`);
}
writeLine("");
}

Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/lsproto/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (r *RequestMessage) UnmarshalJSON(data []byte) error {
type ResponseMessage struct {
JSONRPC JSONRPCVersion `json:"jsonrpc"`
ID *ID `json:"id,omitzero"`
Result any `json:"result"`
Result any `json:"result,omitzero"`
Error *ResponseError `json:"error,omitzero"`
}

Expand Down
17 changes: 17 additions & 0 deletions internal/lsp/lsproto/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ type NotificationInfo[Params any] struct {
_ [0]Params
Method Method
}

type Null struct{}

func (Null) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
data, err := dec.ReadValue()
if err != nil {
return err
}
if string(data) != "null" {
return fmt.Errorf("expected null, got %s", data)
}
return nil
}

func (Null) MarshalJSONTo(enc *jsontext.Encoder) error {
return enc.WriteToken(jsontext.Null)
}
22 changes: 11 additions & 11 deletions internal/lsp/lsproto/lsp_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali

func (s *Server) handleShutdown(ctx context.Context, params any) (lsproto.ShutdownResponse, error) {
s.projectService.Close()
return nil, nil
return lsproto.ShutdownResponse{}, nil
}

func (s *Server) handleExit(ctx context.Context, params any) error {
Expand Down
Loading