@@ -9,6 +9,7 @@ import (
99 "strings"
1010 "time"
1111
12+ "github.com/charmbracelet/crush/internal/csync"
1213 "github.com/charmbracelet/crush/internal/lsp"
1314 "github.com/charmbracelet/x/powernap/pkg/lsp/protocol"
1415)
@@ -18,7 +19,7 @@ type DiagnosticsParams struct {
1819}
1920
2021type diagnosticsTool struct {
21− lspClients map[string]*lsp.Client
22+ lspClients *csync.Map[string, *lsp.Client]
2223}
2324
2425const (
@@ -46,7 +47,7 @@ TIPS:
4647`
4748)
4849
49−func NewDiagnosticsTool(lspClients map[string]*lsp.Client) BaseTool {
50+func NewDiagnosticsTool(lspClients *csync.Map[string, *lsp.Client]) BaseTool {
5051 return &diagnosticsTool{
5152 lspClients,
5253 }
@@ -76,20 +77,19 @@ func (b *diagnosticsTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
7677 return NewTextErrorResponse(fmt.Sprintf("error parsing parameters: %s", err)), nil
7778 }
7879
79− lsps := b.lspClients
80− if len(lsps) == 0 {
80+ if b.lspClients.Len() == 0 {
8181 return NewTextErrorResponse("no LSP clients available"), nil
8282 }
83− notifyLSPs(ctx, lsps, params.FilePath)
84− output := getDiagnostics(params.FilePath, lsps)
83+ notifyLSPs(ctx, b.lspClients, params.FilePath)
84+ output := getDiagnostics(params.FilePath, b.lspClients)
8585 return NewTextResponse(output), nil
8686}
8787
88−func notifyLSPs(ctx context.Context, lsps map[string]*lsp.Client, filepath string) {
88+func notifyLSPs(ctx context.Context, lsps *csync.Map[string, *lsp.Client], filepath string) {
8989 if filepath == "" {
9090 return
9191 }
92− for _, client := range lsps {
92+ for client := range lsps.Seq() {
9393 if !client.HandlesFile(filepath) {
9494 continue
9595 }
@@ -99,11 +99,11 @@ func notifyLSPs(ctx context.Context, lsps map[string]*lsp.Client, filepath strin
9999 }
100100}
101101
102−func getDiagnostics(filePath string, lsps map[string]*lsp.Client) string {
102+func getDiagnostics(filePath string, lsps *csync.Map[string, *lsp.Client]) string {
103103 fileDiagnostics := []string{}
104104 projectDiagnostics := []string{}
105105
106− for lspName, client := range lsps {
106+ for lspName, client := range lsps.Seq2() {
107107 for location, diags := range client.GetDiagnostics() {
108108 path, err := location.Path()
109109 if err != nil {