on main help sign in
perf(lsp): don't watch for changes when simply reading files
commit6604dd0e38440369e98c7462e977bc2e015f292a authorChristian Rocha <christian@rocha.is> dateThu 26 Feb 2026, 13:45 (8 months ago) parent12f0d9f
2 files changed+24−4
internal/agent/tools/diagnostics.go+23−3 internal/agent/tools/view.go+1−1
internal/agent/tools/diagnostics.go+23−3
@@ -37,16 +37,36 @@ func NewDiagnosticsTool(lspManager *lsp.Manager) fantasy.AgentTool {
3737 })
3838}
3939
40−func notifyLSPs(
40+// openInLSPs ensures LSP servers are running and aware of the file, but does
41+// not notify changes or wait for fresh diagnostics. Use this for read-only
42+// operations like view where the file content hasn't changed.
43+func openInLSPs(
4144 ctx context.Context,
4245 manager *lsp.Manager,
4346 filepath string,
4447) {
45− if filepath == "" {
48+ if filepath == "" || manager == nil {
4649 return
4750 }
4851
49− if manager == nil {
52+ manager.Start(ctx, filepath)
53+
54+ for client := range manager.Clients().Seq() {
55+ if !client.HandlesFile(filepath) {
56+ continue
57+ }
58+ _ = client.OpenFileOnDemand(ctx, filepath)
59+ }
60+}
61+
62+// notifyLSPs notifies LSP servers that a file has changed and waits for
63+// updated diagnostics. Use this after edit/multiedit operations.
64+func notifyLSPs(
65+ ctx context.Context,
66+ manager *lsp.Manager,
67+ filepath string,
68+) {
69+ if filepath == "" || manager == nil {
5070 return
5171 }
5272
internal/agent/tools/view.go+1−1
@@ -193,7 +193,7 @@ func NewViewTool(
193193 return fantasy.NewTextErrorResponse("File content is not valid UTF-8"), nil
194194 }
195195
196− notifyLSPs(ctx, lspManager, filePath)
196+ openInLSPs(ctx, lspManager, filePath)
197197 output := "<file>\n"
198198 output += addLineNumbers(content, params.Offset+1)
199199