(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request)
| 265 | } |
| 266 | |
| 267 | func (h *Handler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error) { |
| 268 | defer func() { |
| 269 | if r := recover(); r != nil { |
| 270 | err, ok := r.(error) |
| 271 | if !ok { |
| 272 | err = errors.Errorf("panic: %v", r) |
| 273 | } |
| 274 | slog.Error("Panic in LSP handler", log.BBError(err), slog.String("method", req.Method), log.BBStack("panic-stack")) |
| 275 | } |
| 276 | }() |
| 277 | |
| 278 | // Check token expiry before processing any request |
| 279 | if err := h.checkTokenExpiry(); err != nil { |
| 280 | conn.Close() |
| 281 | return nil, err |
| 282 | } |
| 283 | |
| 284 | // Handle ping request before checking if the server is initialized. |
| 285 | if Method(req.Method) == LSPMethodPing { |
| 286 | return PingResult{Result: "pong"}, nil |
| 287 | } |
| 288 | |
| 289 | if err := h.checkInitialized(req); err != nil { |
| 290 | return nil, err |
| 291 | } |
| 292 | if err := h.checkReady(); err != nil { |
| 293 | return nil, err |
| 294 | } |
| 295 | |
| 296 | switch Method(req.Method) { |
| 297 | case LSPMethodInitialize: |
| 298 | if h.init != nil { |
| 299 | return nil, errors.New("server is already initialized") |
| 300 | } |
| 301 | if req.Params == nil { |
| 302 | return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} |
| 303 | } |
| 304 | var params lsp.InitializeParams |
| 305 | if err := json.Unmarshal(*req.Params, ¶ms); err != nil { |
| 306 | return nil, err |
| 307 | } |
| 308 | |
| 309 | if err := h.reset(¶ms); err != nil { |
| 310 | return nil, err |
| 311 | } |
| 312 | |
| 313 | return lsp.InitializeResult{ |
| 314 | Capabilities: lsp.ServerCapabilities{ |
| 315 | TextDocumentSync: lsp.Incremental, |
| 316 | CompletionProvider: &lsp.CompletionOptions{ |
| 317 | TriggerCharacters: []string{".", " "}, |
| 318 | }, |
| 319 | ExecuteCommandProvider: &lsp.ExecuteCommandOptions{ |
| 320 | Commands: []string{string(CommandNameSetMetadata)}, |
| 321 | }, |
| 322 | }, |
| 323 | }, nil |
| 324 | case LSPMethodInitialized: |
nothing calls this directly
no test coverage detected