diff --git a/internal/agent/tools/diagnostics.go b/internal/agent/tools/diagnostics.go index 41a1b8abfa8e54c32de783cd2bf1da11f3bdf264..3adadd17f70584be221458dda8210f3e644ac4fd 100644 --- a/internal/agent/tools/diagnostics.go +++ b/internal/agent/tools/diagnostics.go @@ -37,16 +37,36 @@ func NewDiagnosticsTool(lspManager *lsp.Manager) fantasy.AgentTool { }) } -func notifyLSPs( +// openInLSPs ensures LSP servers are running and aware of the file, but does +// not notify changes or wait for fresh diagnostics. Use this for read-only +// operations like view where the file content hasn't changed. +func openInLSPs( ctx context.Context, manager *lsp.Manager, filepath string, ) { - if filepath == "" { + if filepath == "" || manager == nil { return } - if manager == nil { + manager.Start(ctx, filepath) + + for client := range manager.Clients().Seq() { + if !client.HandlesFile(filepath) { + continue + } + _ = client.OpenFileOnDemand(ctx, filepath) + } +} + +// notifyLSPs notifies LSP servers that a file has changed and waits for +// updated diagnostics. Use this after edit/multiedit operations. +func notifyLSPs( + ctx context.Context, + manager *lsp.Manager, + filepath string, +) { + if filepath == "" || manager == nil { return } diff --git a/internal/agent/tools/view.go b/internal/agent/tools/view.go index 284ff2decf66ff30454f26277749616bd46bece5..f304e9f7c45c195b6aef7d768b6671c1cdf74e82 100644 --- a/internal/agent/tools/view.go +++ b/internal/agent/tools/view.go @@ -193,7 +193,7 @@ func NewViewTool( return fantasy.NewTextErrorResponse("File content is not valid UTF-8"), nil } - notifyLSPs(ctx, lspManager, filePath) + openInLSPs(ctx, lspManager, filePath) output := "\n" output += addLineNumbers(content, params.Offset+1)