From 7bb3a7ba97706a3bebfedcd364ce5ce6fc5d43a9 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Sun, 22 Mar 2026 11:58:59 +0300 Subject: [PATCH] refactor: simplify LSP diagnostic counts retrieval --- internal/ui/model/lsp.go | 12 +++++------- internal/workspace/client_workspace.go | 24 ++++++++++++++++++++++-- internal/workspace/workspace.go | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/internal/ui/model/lsp.go b/internal/ui/model/lsp.go index c82a4a77b80a5ee258e6d5195bffd1bd7deb76c0..a129a53b619c9bbaef92597b27d99e850319634c 100644 --- a/internal/ui/model/lsp.go +++ b/internal/ui/model/lsp.go @@ -32,13 +32,11 @@ func (m *UI) lspInfo(width, maxItems int, isSection bool) string { var lsps []LSPInfo for _, state := range states { lspErrs := map[protocol.DiagnosticSeverity]int{} - if client, ok := m.com.Workspace.LSPGetClient(state.Name); ok { - counts := client.GetDiagnosticCounts() - lspErrs[protocol.SeverityError] = counts.Error - lspErrs[protocol.SeverityWarning] = counts.Warning - lspErrs[protocol.SeverityHint] = counts.Hint - lspErrs[protocol.SeverityInformation] = counts.Information - } + counts := m.com.Workspace.LSPGetDiagnosticCounts(state.Name) + lspErrs[protocol.SeverityError] = counts.Error + lspErrs[protocol.SeverityWarning] = counts.Warning + lspErrs[protocol.SeverityHint] = counts.Hint + lspErrs[protocol.SeverityInformation] = counts.Information lsps = append(lsps, LSPInfo{LSPClientInfo: state, Diagnostics: lspErrs}) } diff --git a/internal/workspace/client_workspace.go b/internal/workspace/client_workspace.go index 10df76ee536ccb647516f9dad5e16a097ba201b7..7c4e1408882cc70859ea2ab05981461d262513e9 100644 --- a/internal/workspace/client_workspace.go +++ b/internal/workspace/client_workspace.go @@ -22,6 +22,7 @@ import ( "github.com/charmbracelet/crush/internal/proto" "github.com/charmbracelet/crush/internal/pubsub" "github.com/charmbracelet/crush/internal/session" + "github.com/charmbracelet/x/powernap/pkg/lsp/protocol" ) // ClientWorkspace implements the Workspace interface by delegating all @@ -359,8 +360,27 @@ func (w *ClientWorkspace) LSPGetStates() map[string]LSPClientInfo { return result } -func (w *ClientWorkspace) LSPGetClient(_ string) (*lsp.Client, bool) { - return nil, false +func (w *ClientWorkspace) LSPGetDiagnosticCounts(name string) lsp.DiagnosticCounts { + diags, err := w.client.GetLSPDiagnostics(context.Background(), w.workspaceID(), name) + if err != nil { + return lsp.DiagnosticCounts{} + } + var counts lsp.DiagnosticCounts + for _, fileDiags := range diags { + for _, d := range fileDiags { + switch d.Severity { + case protocol.SeverityError: + counts.Error++ + case protocol.SeverityWarning: + counts.Warning++ + case protocol.SeverityInformation: + counts.Information++ + case protocol.SeverityHint: + counts.Hint++ + } + } + } + return counts } // -- Config (read-only) -- diff --git a/internal/workspace/workspace.go b/internal/workspace/workspace.go index 4237ac8ec18234534e616db2d44d1eac52c542f2..02c54c616f3251140bbee441451c3a4cb14845bd 100644 --- a/internal/workspace/workspace.go +++ b/internal/workspace/workspace.go @@ -107,7 +107,7 @@ type Workspace interface { LSPStart(ctx context.Context, path string) LSPStopAll(ctx context.Context) LSPGetStates() map[string]LSPClientInfo - LSPGetClient(name string) (*lsp.Client, bool) + LSPGetDiagnosticCounts(name string) lsp.DiagnosticCounts // Config (read-only data) Config() *config.Config