@@ -324,6 +324,9 @@ type OpenFileInfo struct {
324324// HandlesFile checks if this LSP client handles the given file based on its
325325// extension and whether it's within the working directory.
326326func (c *Client) HandlesFile(path string) bool {
327+ if c == nil {
328+ return false
329+ }
327330 if !fsext.HasPrefix(path, c.cwd) {
328331 slog.Debug("File outside workspace", "name", c.name, "file", path, "workDir", c.cwd)
329332 return false
@@ -364,6 +367,9 @@ func (c *Client) OpenFile(ctx context.Context, filepath string) error {
364367
365368// NotifyChange notifies the server about a file change.
366369func (c *Client) NotifyChange(ctx context.Context, filepath string) error {
370+ if c == nil {
371+ return nil
372+ }
367373 uri := string(protocol.URIFromPath(filepath))
368374
369375 content, err := os.ReadFile(filepath)
@@ -420,12 +426,18 @@ func (c *Client) GetFileDiagnostics(uri protocol.DocumentURI) []protocol.Diagnos
420426
421427// GetDiagnostics returns all diagnostics for all files.
422428func (c *Client) GetDiagnostics() map[protocol.DocumentURI][]protocol.Diagnostic {
429+ if c == nil {
430+ return nil
431+ }
423432 return c.diagnostics.Copy()
424433}
425434
426435// GetDiagnosticCounts returns cached diagnostic counts by severity.
427436// Uses the VersionedMap version to avoid recomputing on every call.
428437func (c *Client) GetDiagnosticCounts() DiagnosticCounts {
438+ if c == nil {
439+ return DiagnosticCounts{}
440+ }
429441 currentVersion := c.diagnostics.Version()
430442
431443 c.diagCountsMu.Lock()
@@ -459,6 +471,9 @@ func (c *Client) GetDiagnosticCounts() DiagnosticCounts {
459471
460472// OpenFileOnDemand opens a file only if it's not already open.
461473func (c *Client) OpenFileOnDemand(ctx context.Context, filepath string) error {
474+ if c == nil {
475+ return nil
476+ }
462477 // Check if the file is already open
463478 if c.IsFileOpen(filepath) {
464479 return nil
@@ -501,6 +516,9 @@ func (c *Client) openKeyConfigFiles(ctx context.Context) {
501516
502517// WaitForDiagnostics waits until diagnostics change or the timeout is reached.
503518func (c *Client) WaitForDiagnostics(ctx context.Context, d time.Duration) {
519+ if c == nil {
520+ return
521+ }
504522 ticker := time.NewTicker(200 * time.Millisecond)
505523 defer ticker.Stop()
506524 timeout := time.After(d)