summaryrefslogtreecommitdiffhomepage
path: root/internal/app
diff options
context:
space:
mode:
Diffstat (limited to 'internal/app')
-rw-r--r--internal/app/app.go3
-rw-r--r--internal/app/lsp.go29
2 files changed, 27 insertions, 5 deletions
diff --git a/internal/app/app.go b/internal/app/app.go
index 8f4f5e098..36b1ca16f 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -49,7 +49,8 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
LSPClients: make(map[string]*lsp.Client),
}
- app.initLSPClients(ctx)
+ // Initialize LSP clients in the background
+ go app.initLSPClients(ctx)
var err error
app.CoderAgent, err = agent.NewAgent(
diff --git a/internal/app/lsp.go b/internal/app/lsp.go
index d8a35c8b3..77feeb943 100644
--- a/internal/app/lsp.go
+++ b/internal/app/lsp.go
@@ -15,24 +15,28 @@ func (app *App) initLSPClients(ctx context.Context) {
// Initialize LSP clients
for name, clientConfig := range cfg.LSP {
- app.createAndStartLSPClient(ctx, name, clientConfig.Command, clientConfig.Args...)
+ // Start each client initialization in its own goroutine
+ go app.createAndStartLSPClient(ctx, name, clientConfig.Command, clientConfig.Args...)
}
+ logging.Info("LSP clients initialization started in background")
}
// createAndStartLSPClient creates a new LSP client, initializes it, and starts its workspace watcher
func (app *App) createAndStartLSPClient(ctx context.Context, name string, command string, args ...string) {
// Create a specific context for initialization with a timeout
-
+ logging.Info("Creating LSP client", "name", name, "command", command, "args", args)
+
// Create the LSP client
lspClient, err := lsp.NewClient(ctx, command, args...)
if err != nil {
logging.Error("Failed to create LSP client for", name, err)
return
-
}
- initCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
+ // Create a longer timeout for initialization (some servers take time to start)
+ initCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
+
// Initialize with the initialization context
_, err = lspClient.InitializeLSPClient(initCtx, config.WorkingDirectory())
if err != nil {
@@ -42,8 +46,25 @@ func (app *App) createAndStartLSPClient(ctx context.Context, name string, comman
return
}
+ // Wait for the server to be ready
+ if err := lspClient.WaitForServerReady(initCtx); err != nil {
+ logging.Error("Server failed to become ready", "name", name, "error", err)
+ // We'll continue anyway, as some functionality might still work
+ lspClient.SetServerState(lsp.StateError)
+ } else {
+ logging.Info("LSP server is ready", "name", name)
+ lspClient.SetServerState(lsp.StateReady)
+ }
+
+ logging.Info("LSP client initialized", "name", name)
+
// Create a child context that can be canceled when the app is shutting down
watchCtx, cancelFunc := context.WithCancel(ctx)
+
+ // Create a context with the server name for better identification
+ watchCtx = context.WithValue(watchCtx, "serverName", name)
+
+ // Create the workspace watcher
workspaceWatcher := watcher.NewWorkspaceWatcher(lspClient)
// Store the cancel function to be called during cleanup