on main help sign in
perf(lsp): use shared timeout for parallel diagnostics collection
d98c854Christian Rocha
internal/agent/tools/diagnostics.go+11−1
@@ -7,6 +7,7 @@ import (
7 "log/slog"
7 "log/slog"
8 "sort"
8 "sort"
9 "strings"
9 "strings"
10+ "sync"
10 "time"
11 "time"
11
12
12 "charm.land/fantasy"
13 "charm.land/fantasy"
@@ -72,12 +73,21 @@ func waitForLSPDiagnostics(
72 return
73 return
73 }
74 }
74
75
76+ waitCtx, cancel := context.WithTimeout(ctx, timeout)
77+ defer cancel()
78+
79+ var wg sync.WaitGroup
75 for client := range manager.Clients().Seq() {
80 for client := range manager.Clients().Seq() {
76 if !client.HandlesFile(filepath) {
81 if !client.HandlesFile(filepath) {
77 continue
82 continue
78 }
83 }
84+ wg.Add(1)
85+ go func() {
86+ defer wg.Done()
79− client.WaitForDiagnostics(ctx, timeout)
87+ client.WaitForDiagnostics(waitCtx, timeout)
88+ }()
80 }
89 }
90+ wg.Wait()
81}
91}
82
92
83// notifyLSPs notifies LSP servers that a file has changed and waits for
93// notifyLSPs notifies LSP servers that a file has changed and waits for