Improve LSP diagnostics handling for file operations

- 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 <noreply@termai.io>
This commit is contained in:
Kujtim Hoxha
2025-04-04 15:03:50 +02:00
parent a1f6147506
commit 3aef4dedcf
3 changed files with 38 additions and 12 deletions

View File

@@ -100,7 +100,6 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
return NewTextErrorResponse(fmt.Sprintf("Failed to create parent directories: %s", err)), nil
}
notifyLspOpenFile(ctx, filePath, w.lspClients)
// Get old content for diff if file exists
oldContent := ""
if fileInfo != nil && !fileInfo.IsDir() {
@@ -135,6 +134,8 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
// Record the file write
recordFileWrite(filePath)
recordFileRead(filePath)
// Wait for LSP diagnostics after writing the file
waitForLspDiagnostics(ctx, filePath, w.lspClients)
result := fmt.Sprintf("File successfully written: %s", filePath)
result = fmt.Sprintf("<result>\n%s\n</result>", result)