{"record":{"id":"f6262483c358381c","repo":"charmbracelet/crush","slug":"failed-to-initialize-the-lsp-client-w","errorCode":null,"errorMessage":"failed to initialize the lsp client: %w","messagePattern":"failed to initialize the lsp client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/client.go","lineNumber":114,"sourceCode":"\n\tif err := client.createPowernapClient(); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn client, nil\n}\n\n// Initialize initializes the LSP client and returns the server capabilities.\nfunc (c *Client) Initialize(ctx context.Context, workspaceDir string) (*protocol.InitializeResult, error) {\n\t// Register handlers for requests the server may send during the\n\t// initialize handshake itself (e.g. typescript-language-server issuing\n\t// window/workDoneProgress/create while loading the project, before\n\t// initialize has returned). Registering after client.Initialize() is too\n\t// late for those — the server treats an unhandled response as fatal.\n\tc.registerHandlers()\n\n\tif err := c.client.Initialize(ctx, false); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to initialize the lsp client: %w\", err)\n\t}\n\n\t// Convert powernap capabilities to protocol capabilities\n\tcaps := c.client.GetCapabilities()\n\tprotocolCaps := protocol.ServerCapabilities{\n\t\tTextDocumentSync: caps.TextDocumentSync,\n\t\tCompletionProvider: func() *protocol.CompletionOptions {\n\t\t\tif caps.CompletionProvider != nil {\n\t\t\t\treturn &protocol.CompletionOptions{\n\t\t\t\t\tTriggerCharacters:   caps.CompletionProvider.TriggerCharacters,\n\t\t\t\t\tAllCommitCharacters: caps.CompletionProvider.AllCommitCharacters,\n\t\t\t\t\tResolveProvider:     caps.CompletionProvider.ResolveProvider,\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t}(),\n\t}\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/lsp/client.go#L96-L132","documentation":"The LSP client's Initialize method calls the underlying powernap client's Initialize (the LSP `initialize` handshake). If that request fails or the server errors/times out, this error wraps the cause. Handlers are registered before this call precisely so requests sent during initialization (e.g. workDoneProgress/create) are answered; failing means the server never completed the handshake.","triggerScenarios":"Calling Initialize when the LSP server binary is missing or crashes at startup, the server sends an unhandled request/response during initialize, the connection drops, or the context deadline expires before the server responds.","commonSituations":"LSP binary not installed or not on PATH; misconfigured LSP command in crushrc (wrong args, wrong cwd); the server version doesn't match the expected protocol behavior; server crashed while loading a large project; timeout too short for slow startup.","solutions":["Check the wrapped error for the root cause (process not found, timeout, protocol error) and fix that first.","Verify the LSP server command and args configured for the language are correct and the binary is installed/on PATH.","Run the server manually with the same args to confirm it starts and speaks the expected protocol version.","Increase the initialization timeout for slow-starting servers or large workspaces.","Restart the LSP client (client.Restart) after fixing the server configuration."],"exampleFix":"// before (crushrc)\nlsp gopls \"gopls\" \"wrong-flag\"\n// after\nlsp gopls \"gopls\" \"serve\"\n// ensure gopls is installed:\n// go install golang.org/x/tools/gopls@latest","handlingStrategy":"try-catch","validationCode":"// verify the server binary is runnable before initializing\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\nif err := exec.CommandContext(ctx, cmd, args...).Run(); err != nil {\n    return fmt.Errorf(\"LSP server %q is not runnable: %w\", cmd, err)\n}","typeGuard":null,"tryCatchPattern":"client, err := lspClient.Initialize(ctx)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        return fmt.Errorf(\"LSP server did not respond in time; retry with a longer timeout\")\n    }\n    return fmt.Errorf(\"LSP init failed, check server install/config: %w\", err)\n}","preventionTips":["Verify the language server binary is installed and on PATH before startup.","Validate the LSP command/args in crushrc against the server's documented CLI.","Allow generous initialization timeouts for large projects and slow disks.","Keep the LSP server version current with the protocol the client expects."],"tags":["lsp","initialization","language-server","protocol"],"backgroundTag":"lsp-initialize-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}