Skip to content

Commit

Permalink
lsp: Support lsp client shutdown message (#539)
Browse files Browse the repository at this point in the history
This message also doesn't have params, and so we need to make sure we
handle that correctly in the debug logging.

Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 authored Feb 6, 2024
1 parent bc27c76 commit f2d07d9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (l *LanguageServer) Handle(
conn *jsonrpc2.Conn,
req *jsonrpc2.Request,
) (result any, err error) {
l.logInboundMessage(req.Method, string(*req.Params))
if req.Params == nil {
l.logInboundMessage(req.Method, "empty params")
} else {
l.logInboundMessage(req.Method, string(*req.Params))
}

if req.Params == nil {
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
Expand Down Expand Up @@ -88,6 +92,13 @@ func (l *LanguageServer) Handle(
return l.handleWorkspaceDidDeleteFiles(ctx, conn, req)
case "workspace/didCreateFiles":
return l.handleWorkspaceDidCreateFiles(ctx, conn, req)
case "shutdown":
err = conn.Close()
if err != nil {
return nil, fmt.Errorf("failed to close connection: %w", err)
}

return struct{}{}, nil
}

return nil, &jsonrpc2.Error{
Expand Down

0 comments on commit f2d07d9

Please sign in to comment.