diff --git a/internal/app/lsp.go b/internal/app/lsp.go index fb95b7747ff5be1a1c4b56e01befc2b3c5edd70c..a93fadbd1869f46bb153e19fa15428f74293b7fc 100644 --- a/internal/app/lsp.go +++ b/internal/app/lsp.go @@ -1,6 +1,7 @@ package app import ( + "cmp" "context" "log/slog" "os/exec" @@ -69,7 +70,7 @@ func (app *App) initLSPClients(ctx context.Context) { wg.Go(func() { app.createAndStartLSPClient( ctx, name, - toOurConfig(server), + toOurConfig(server, app.config.LSP[name]), slices.Contains(userConfiguredLSPs, name), ) }) @@ -83,7 +84,9 @@ func (app *App) initLSPClients(ctx context.Context) { } } -func toOurConfig(in *powernapconfig.ServerConfig) config.LSPConfig { +// toOurConfig merges powernap default config with user config. +// If user config is zero value, it means no user override exists. +func toOurConfig(in *powernapconfig.ServerConfig, user config.LSPConfig) config.LSPConfig { return config.LSPConfig{ Command: in.Command, Args: in.Args, @@ -92,6 +95,7 @@ func toOurConfig(in *powernapconfig.ServerConfig) config.LSPConfig { RootMarkers: in.RootMarkers, InitOptions: in.InitOptions, Options: in.Settings, + Timeout: user.Timeout, } } @@ -126,7 +130,7 @@ func (app *App) createAndStartLSPClient(ctx context.Context, name string, config lspClient.SetDiagnosticsCallback(updateLSPDiagnostics) // Increase initialization timeout as some servers take more time to start. - initCtx, cancel := context.WithTimeout(ctx, 30*time.Second) + initCtx, cancel := context.WithTimeout(ctx, time.Duration(cmp.Or(config.Timeout, 30))*time.Second) defer cancel() // Initialize LSP client. diff --git a/internal/config/config.go b/internal/config/config.go index 19133928bd8f7e1da08b54024b4f80d41d01dc1a..0e475ee89654914722b829aaea4d1b7830618914 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -194,6 +194,7 @@ type LSPConfig struct { RootMarkers []string `json:"root_markers,omitempty" jsonschema:"description=Files or directories that indicate the project root,example=go.mod,example=package.json,example=Cargo.toml"` InitOptions map[string]any `json:"init_options,omitempty" jsonschema:"description=Initialization options passed to the LSP server during initialize request"` Options map[string]any `json:"options,omitempty" jsonschema:"description=LSP server-specific settings passed during initialization"` + Timeout int `json:"timeout,omitempty" jsonschema:"description=Timeout in seconds for LSP server initialization,default=30,example=60,example=120"` } type TUIOptions struct { diff --git a/schema.json b/schema.json index 7a32f612e64a20d0393f74471c1fbdb8863c2365..daf8dc6f29794446ace635b656099150c5b82901 100644 --- a/schema.json +++ b/schema.json @@ -156,6 +156,15 @@ "options": { "type": "object", "description": "LSP server-specific settings passed during initialization" + }, + "timeout": { + "type": "integer", + "description": "Timeout in seconds for LSP server initialization", + "default": 30, + "examples": [ + 60, + 120 + ] } }, "additionalProperties": false,