Skip to content

Commit 4d28085

Browse files
skewb1kjakebailey
andauthored
fix: make ResponseMessage.Result omitzero (#1533)
Co-authored-by: Jake Bailey <[email protected]>
1 parent a09ce52 commit 4d28085

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

internal/lsp/lsproto/_generate/generate.mts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,16 @@ function generateCode() {
704704
}
705705

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

710-
writeLine(`type ${responseTypeName} = ${goType}`);
708+
// Special case for response types that are explicitly base type "null"
709+
if (request.result.kind === "base" && request.result.name === "null") {
710+
writeLine(`type ${responseTypeName} = Null`);
711+
}
712+
else {
713+
const resultType = resolveType(request.result);
714+
const goType = resultType.needsPointer ? `*${resultType.name}` : resultType.name;
715+
writeLine(`type ${responseTypeName} = ${goType}`);
716+
}
711717
writeLine("");
712718
}
713719

internal/lsp/lsproto/jsonrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (r *RequestMessage) UnmarshalJSON(data []byte) error {
207207
type ResponseMessage struct {
208208
JSONRPC JSONRPCVersion `json:"jsonrpc"`
209209
ID *ID `json:"id,omitzero"`
210-
Result any `json:"result"`
210+
Result any `json:"result,omitzero"`
211211
Error *ResponseError `json:"error,omitzero"`
212212
}
213213

internal/lsp/lsproto/lsp.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,20 @@ type NotificationInfo[Params any] struct {
8383
_ [0]Params
8484
Method Method
8585
}
86+
87+
type Null struct{}
88+
89+
func (Null) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
90+
data, err := dec.ReadValue()
91+
if err != nil {
92+
return err
93+
}
94+
if string(data) != "null" {
95+
return fmt.Errorf("expected null, got %s", data)
96+
}
97+
return nil
98+
}
99+
100+
func (Null) MarshalJSONTo(enc *jsontext.Encoder) error {
101+
return enc.WriteToken(jsontext.Null)
102+
}

internal/lsp/lsproto/lsp_generated.go

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lsp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali
660660

661661
func (s *Server) handleShutdown(ctx context.Context, params any) (lsproto.ShutdownResponse, error) {
662662
s.projectService.Close()
663-
return nil, nil
663+
return lsproto.ShutdownResponse{}, nil
664664
}
665665

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

0 commit comments

Comments
 (0)