on main help sign in
refactor: simplify LSP diagnostic counts retrieval
commit7bb3a7ba97706a3bebfedcd364ce5ce6fc5d43a9 authorAyman Bagabas <ayman.bagabas@gmail.com> dateSun 22 Mar 2026, 11:58 (7 months ago) parenta35a2bd
3 files changed+28−10
internal/ui/model/lsp.go+5−7 internal/workspace/client_workspace.go+22−2 internal/workspace/workspace.go+1−1
internal/ui/model/lsp.go+5−7
@@ -32,13 +32,11 @@ func (m *UI) lspInfo(width, maxItems int, isSection bool) string {
3232 var lsps []LSPInfo
3333 for _, state := range states {
3434 lspErrs := map[protocol.DiagnosticSeverity]int{}
35− if client, ok := m.com.Workspace.LSPGetClient(state.Name); ok {
36− counts := client.GetDiagnosticCounts()
37− lspErrs[protocol.SeverityError] = counts.Error
38− lspErrs[protocol.SeverityWarning] = counts.Warning
39− lspErrs[protocol.SeverityHint] = counts.Hint
40− lspErrs[protocol.SeverityInformation] = counts.Information
41− }
35+ counts := m.com.Workspace.LSPGetDiagnosticCounts(state.Name)
36+ lspErrs[protocol.SeverityError] = counts.Error
37+ lspErrs[protocol.SeverityWarning] = counts.Warning
38+ lspErrs[protocol.SeverityHint] = counts.Hint
39+ lspErrs[protocol.SeverityInformation] = counts.Information
4240
4341 lsps = append(lsps, LSPInfo{LSPClientInfo: state, Diagnostics: lspErrs})
4442 }
internal/workspace/client_workspace.go+22−2
@@ -22,6 +22,7 @@ import (
2222 "github.com/charmbracelet/crush/internal/proto"
2323 "github.com/charmbracelet/crush/internal/pubsub"
2424 "github.com/charmbracelet/crush/internal/session"
25+ "github.com/charmbracelet/x/powernap/pkg/lsp/protocol"
2526)
2627
2728// ClientWorkspace implements the Workspace interface by delegating all
@@ -359,8 +360,27 @@ func (w *ClientWorkspace) LSPGetStates() map[string]LSPClientInfo {
359360 return result
360361}
361362
362−func (w *ClientWorkspace) LSPGetClient(_ string) (*lsp.Client, bool) {
363− return nil, false
363+func (w *ClientWorkspace) LSPGetDiagnosticCounts(name string) lsp.DiagnosticCounts {
364+ diags, err := w.client.GetLSPDiagnostics(context.Background(), w.workspaceID(), name)
365+ if err != nil {
366+ return lsp.DiagnosticCounts{}
367+ }
368+ var counts lsp.DiagnosticCounts
369+ for _, fileDiags := range diags {
370+ for _, d := range fileDiags {
371+ switch d.Severity {
372+ case protocol.SeverityError:
373+ counts.Error++
374+ case protocol.SeverityWarning:
375+ counts.Warning++
376+ case protocol.SeverityInformation:
377+ counts.Information++
378+ case protocol.SeverityHint:
379+ counts.Hint++
380+ }
381+ }
382+ }
383+ return counts
364384}
365385
366386// -- Config (read-only) --
internal/workspace/workspace.go+1−1
@@ -107,7 +107,7 @@ type Workspace interface {
107107 LSPStart(ctx context.Context, path string)
108108 LSPStopAll(ctx context.Context)
109109 LSPGetStates() map[string]LSPClientInfo
110− LSPGetClient(name string) (*lsp.Client, bool)
110+ LSPGetDiagnosticCounts(name string) lsp.DiagnosticCounts
111111
112112 // Config (read-only data)
113113 Config() *config.Config