@@ -9,6 +9,7 @@ import (
12+ "github.com/charmbracelet/crush/internal/csync"
12 "github.com/charmbracelet/crush/internal/lsp"
13 "github.com/charmbracelet/crush/internal/lsp"
13 "github.com/charmbracelet/x/powernap/pkg/lsp/protocol"
14 "github.com/charmbracelet/x/powernap/pkg/lsp/protocol"
@@ -18,7 +19,7 @@ type DiagnosticsParams struct {
20type diagnosticsTool struct {
21type diagnosticsTool struct {
21− lspClients map[string]*lsp.Client
22+ lspClients *csync.Map[string, *lsp.Client]
@@ -46,7 +47,7 @@ TIPS:
49−func NewDiagnosticsTool(lspClients map[string]*lsp.Client) BaseTool {
50+func NewDiagnosticsTool(lspClients *csync.Map[string, *lsp.Client]) BaseTool {
50 return &diagnosticsTool{
51 return &diagnosticsTool{
51 lspClients,
52 lspClients,
@@ -76,20 +77,19 @@ func (b *diagnosticsTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
76 return NewTextErrorResponse(fmt.Sprintf("error parsing parameters: %s", err)), nil
77 return NewTextErrorResponse(fmt.Sprintf("error parsing parameters: %s", err)), nil
79− lsps := b.lspClients
80+ if b.lspClients.Len() == 0 {
81 return NewTextErrorResponse("no LSP clients available"), nil
81 return NewTextErrorResponse("no LSP clients available"), nil
83− notifyLSPs(ctx, lsps, params.FilePath)
83+ notifyLSPs(ctx, b.lspClients, params.FilePath)
84− output := getDiagnostics(params.FilePath, lsps)
84+ output := getDiagnostics(params.FilePath, b.lspClients)
85 return NewTextResponse(output), nil
85 return NewTextResponse(output), nil
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) {
89 if filepath == "" {
89 if filepath == "" {
92− for _, client := range lsps {
92+ for client := range lsps.Seq() {
93 if !client.HandlesFile(filepath) {
93 if !client.HandlesFile(filepath) {
@@ -99,11 +99,11 @@ func notifyLSPs(ctx context.Context, lsps map[string]*lsp.Client, filepath strin
102−func getDiagnostics(filePath string, lsps map[string]*lsp.Client) string {
102+func getDiagnostics(filePath string, lsps *csync.Map[string, *lsp.Client]) string {
103 fileDiagnostics := []string{}
103 fileDiagnostics := []string{}
104 projectDiagnostics := []string{}
104 projectDiagnostics := []string{}
106− for lspName, client := range lsps {
106+ for lspName, client := range lsps.Seq2() {
107 for location, diags := range client.GetDiagnostics() {
107 for location, diags := range client.GetDiagnostics() {
108 path, err := location.Path()
108 path, err := location.Path()
109 if err != nil {
109 if err != nil {