8 "github.com/charmbracelet/crush/internal/config"
9 "github.com/charmbracelet/crush/internal/lsp"
12// initLSPClients initializes LSP clients.
13func (app *App) initLSPClients(ctx context.Context) {
14 for name, clientConfig := range app.config.LSP {
15 if clientConfig.Disabled {
16 slog.Info("Skipping disabled LSP client", "name", name)
19 go app.createAndStartLSPClient(ctx, name, clientConfig)
21 slog.Info("LSP clients initialization started in background")
24// createAndStartLSPClient creates a new LSP client, initializes it, and starts its workspace watcher
25func (app *App) createAndStartLSPClient(ctx context.Context, name string, config config.LSPConfig) {
26 slog.Debug("Creating LSP client", "name", name, "command", config.Command, "fileTypes", config.FileTypes, "args", config.Args)
28 // Check if any root markers exist in the working directory (config now has defaults)
29 if !lsp.HasRootMarkers(app.config.WorkingDir(), config.RootMarkers) {
30 slog.Debug("Skipping LSP client: no root markers found", "name", name, "rootMarkers", config.RootMarkers)
31 updateLSPState(name, lsp.StateDisabled, nil, nil, 0)
35 // Update state to starting
36 updateLSPState(name, lsp.StateStarting, nil, nil, 0)
39 lspClient, err := lsp.New(ctx, name, config, app.config.Resolver())
41 slog.Error("Failed to create LSP client for", name, err)
42 updateLSPState(name, lsp.StateError, err, nil, 0)
46 // Set diagnostics callback
47 lspClient.SetDiagnosticsCallback(updateLSPDiagnostics)
49 // Increase initialization timeout as some servers take more time to start.
50 initCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
53 // Initialize LSP client.
54 _, err = lspClient.Initialize(initCtx, app.config.WorkingDir())
56 slog.Error("LSP client initialization failed", "name", name, "error", err)
57 updateLSPState(name, lsp.StateError, err, lspClient, 0)
62 // Wait for the server to be ready.
63 if err := lspClient.WaitForServerReady(initCtx); err != nil {
64 slog.Error("Server failed to become ready", "name", name, "error", err)
65 // Server never reached a ready state, but let's continue anyway, as
66 // some functionality might still work.
67 lspClient.SetServerState(lsp.StateError)
68 updateLSPState(name, lsp.StateError, err, lspClient, 0)
70 // Server reached a ready state scuccessfully.
71 slog.Debug("LSP server is ready", "name", name)
72 lspClient.SetServerState(lsp.StateReady)
73 updateLSPState(name, lsp.StateReady, nil, lspClient, 0)
76 slog.Info("LSP client initialized", "name", name)
78 // Add to map with mutex protection before starting goroutine
79 app.LSPClients.Set(name, lspClient)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list