diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-19 15:15:29 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-21 13:42:29 +0200 |
| commit | 2b5a33e476ae3c6b5c6345777d20792786836dda (patch) | |
| tree | ca22c0a7d6c8f73a21e2b67f31b927b7df187d4d /internal/app | |
| parent | bf8cd3bd128d97cf93fcd1481c37db0e46945fd2 (diff) | |
| download | opencode-2b5a33e476ae3c6b5c6345777d20792786836dda.tar.gz opencode-2b5a33e476ae3c6b5c6345777d20792786836dda.zip | |
lsp improvements
Diffstat (limited to 'internal/app')
| -rw-r--r-- | internal/app/app.go | 3 | ||||
| -rw-r--r-- | internal/app/lsp.go | 29 |
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 |
