@@ -35,6 +35,7 @@ type DiagnosticCounts struct {
3535type Client struct {
3636 client *powernap.Client
3737 name string
38+ debug bool
3839
3940 // Working directory this LSP is scoped to.
4041 workDir string
@@ -68,7 +69,7 @@ type Client struct {
6869}
6970
7071// New creates a new LSP client using the powernap implementation.
71−func New(ctx context.Context, name string, cfg config.LSPConfig, resolver config.VariableResolver) (*Client, error) {
72+func New(ctx context.Context, name string, cfg config.LSPConfig, resolver config.VariableResolver, debug bool) (*Client, error) {
7273 client := &Client{
7374 name: name,
7475 fileTypes: cfg.FileTypes,
@@ -76,6 +77,7 @@ func New(ctx context.Context, name string, cfg config.LSPConfig, resolver config
7677 openFiles: csync.NewMap[string, *OpenFileInfo](),
7778 config: cfg,
7879 ctx: ctx,
80+ debug: debug,
7981 resolver: resolver,
8082 }
8183 client.serverState.Store(StateStarting)
@@ -174,7 +176,11 @@ func (c *Client) registerHandlers() {
174176 c.RegisterServerRequestHandler("workspace/applyEdit", HandleApplyEdit)
175177 c.RegisterServerRequestHandler("workspace/configuration", HandleWorkspaceConfiguration)
176178 c.RegisterServerRequestHandler("client/registerCapability", HandleRegisterCapability)
177− c.RegisterNotificationHandler("window/showMessage", HandleServerMessage)
179+ c.RegisterNotificationHandler("window/showMessage", func(ctx context.Context, method string, params json.RawMessage) {
180+ if c.debug {
181+ HandleServerMessage(ctx, method, params)
182+ }
183+ })
178184 c.RegisterNotificationHandler("textDocument/publishDiagnostics", func(_ context.Context, _ string, params json.RawMessage) {
179185 HandleDiagnostics(c, params)
180186 })
@@ -262,8 +268,6 @@ func (c *Client) SetDiagnosticsCallback(callback func(name string, count int)) {
262268
263269// WaitForServerReady waits for the server to be ready
264270func (c *Client) WaitForServerReady(ctx context.Context) error {
265− cfg := config.Get()
266−
267271 // Set initial state
268272 c.SetServerState(StateStarting)
269273
@@ -275,7 +279,7 @@ func (c *Client) WaitForServerReady(ctx context.Context) error {
275279 ticker := time.NewTicker(500 * time.Millisecond)
276280 defer ticker.Stop()
277281
278− if cfg != nil && cfg.Options.DebugLSP {
282+ if c.debug {
279283 slog.Debug("Waiting for LSP server to be ready...")
280284 }
281285
@@ -289,7 +293,7 @@ func (c *Client) WaitForServerReady(ctx context.Context) error {
289293 case <-ticker.C:
290294 // Check if client is running
291295 if !c.client.IsRunning() {
292− if cfg != nil && cfg.Options.DebugLSP {
296+ if c.debug {
293297 slog.Debug("LSP server not ready yet", "server", c.name)
294298 }
295299 continue
@@ -297,7 +301,7 @@ func (c *Client) WaitForServerReady(ctx context.Context) error {
297301
298302 // Server is ready
299303 c.SetServerState(StateReady)
300− if cfg != nil && cfg.Options.DebugLSP {
304+ if c.debug {
301305 slog.Debug("LSP server is ready")
302306 }
303307 return nil
@@ -416,10 +420,8 @@ func (c *Client) IsFileOpen(filepath string) bool {
416420
417421// CloseAllFiles closes all currently open files.
418422func (c *Client) CloseAllFiles(ctx context.Context) {
419− cfg := config.Get()
420− debugLSP := cfg != nil && cfg.Options.DebugLSP
421423 for uri := range c.openFiles.Seq2() {
422− if debugLSP {
424+ if c.debug {
423425 slog.Debug("Closing file", "file", uri)
424426 }
425427 if err := c.client.NotifyDidCloseTextDocument(ctx, uri); err != nil {