From 3aef4dedcfd1ad408c6cb6c06e5e731feb528a1e Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Fri, 4 Apr 2025 15:03:50 +0200 Subject: Improve LSP diagnostics handling for file operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Split LSP file notification into separate functions - Add waitForLspDiagnostics function to wait for diagnostics after file changes - Move LSP diagnostics to after file operations in edit and write tools - Fix string splitting in diff generation - Reduce diagnostics timeout from 10 to 5 seconds 🤖 Generated with termai Co-Authored-By: termai --- internal/llm/tools/edit.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'internal/llm/tools/edit.go') diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go index 394ce13b9..f158401b8 100644 --- a/internal/llm/tools/edit.go +++ b/internal/llm/tools/edit.go @@ -74,7 +74,6 @@ func (e *editTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) params.FilePath = filepath.Join(wd, params.FilePath) } - notifyLspOpenFile(ctx, params.FilePath, e.lspClients) if params.OldString == "" { result, err := createNewFile(params.FilePath, params.NewString) if err != nil { @@ -96,6 +95,8 @@ func (e *editTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) return NewTextErrorResponse(fmt.Sprintf("error replacing content: %s", err)), nil } + // Wait for LSP diagnostics after editing the file + waitForLspDiagnostics(ctx, params.FilePath, e.lspClients) result = fmt.Sprintf("\n%s\n\n", result) result += appendDiagnostics(params.FilePath, e.lspClients) return NewTextResponse(result), nil @@ -303,23 +304,23 @@ func GenerateDiff(oldContent, newContent string) string { diffs = dmp.DiffCharsToLines(diffs, dmpStrings) diffs = dmp.DiffCleanupSemantic(diffs) buff := strings.Builder{} - + // Add a header to make the diff more readable buff.WriteString("Changes:\n") - + for _, diff := range diffs { text := diff.Text switch diff.Type { case diffmatchpatch.DiffInsert: - for _, line := range strings.Split(text, "\n") { + for line := range strings.SplitSeq(text, "\n") { if line == "" { continue } _, _ = buff.WriteString("+ " + line + "\n") } case diffmatchpatch.DiffDelete: - for _, line := range strings.Split(text, "\n") { + for line := range strings.SplitSeq(text, "\n") { if line == "" { continue } -- cgit v1.2.3