on main help sign in
perf(tools/view): pause briefly for LSP diagnostics when viewing a file
commit3c5fcff3855762e6d24cf19fd45d8d69253ee594 authorChristian Rocha <christian@rocha.is> dateThu 26 Feb 2026, 13:52 (8 months ago) parent6604dd0
2 files changed+23
internal/agent/tools/diagnostics.go+21 internal/agent/tools/view.go+2
internal/agent/tools/diagnostics.go+21
@@ -59,6 +59,27 @@ func openInLSPs(
5959 }
6060}
6161
62+// waitForLSPDiagnostics waits briefly for diagnostics publication after a file
63+// has been opened. Intended for read-only situations where viewing up-to-date
64+// files matters but latency should remain low (i.e. when using the view tool).
65+func waitForLSPDiagnostics(
66+ ctx context.Context,
67+ manager *lsp.Manager,
68+ filepath string,
69+ timeout time.Duration,
70+) {
71+ if filepath == "" || manager == nil || timeout <= 0 {
72+ return
73+ }
74+
75+ for client := range manager.Clients().Seq() {
76+ if !client.HandlesFile(filepath) {
77+ continue
78+ }
79+ client.WaitForDiagnostics(ctx, timeout)
80+ }
81+}
82+
6283// notifyLSPs notifies LSP servers that a file has changed and waits for
6384// updated diagnostics. Use this after edit/multiedit operations.
6485func notifyLSPs(
internal/agent/tools/view.go+2
@@ -10,6 +10,7 @@ import (
1010 "os"
1111 "path/filepath"
1212 "strings"
13+ "time"
1314 "unicode/utf8"
1415
1516 "charm.land/fantasy"
@@ -194,6 +195,7 @@ func NewViewTool(
194195 }
195196
196197 openInLSPs(ctx, lspManager, filePath)
198+ waitForLSPDiagnostics(ctx, lspManager, filePath, 300*time.Millisecond)
197199 output := "<file>\n"
198200 output += addLineNumbers(content, params.Offset+1)
199201