From 65c9fcd54f9c1b163c43e34e90ac3fcfb9c7c34b Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 6 May 2025 20:10:51 +0800 Subject: [PATCH] fix: more robust diff blocks parser (#1994) --- lua/avante/llm_tools/replace_in_file.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/avante/llm_tools/replace_in_file.lua b/lua/avante/llm_tools/replace_in_file.lua index a5495cc..86bd83f 100644 --- a/lua/avante/llm_tools/replace_in_file.lua +++ b/lua/avante/llm_tools/replace_in_file.lua @@ -89,15 +89,15 @@ function M.func(opts, on_log, on_complete, session_ctx) local rough_diff_blocks = {} for _, line in ipairs(diff_lines) do - if line:match("^%s*<<<<<<< SEARCH") then + if line:match("^%s*<<<<<<<* SEARCH") then is_searching = true is_replacing = false current_search = {} - elseif line:match("^%s*=======") and is_searching then + elseif line:match("^%s*=======*") and is_searching then is_searching = false is_replacing = true current_replace = {} - elseif line:match("^%s*>>>>>>> REPLACE") and is_replacing then + elseif line:match("^%s*>>>>>>>* REPLACE") and is_replacing then is_replacing = false table.insert( rough_diff_blocks, @@ -110,7 +110,10 @@ function M.func(opts, on_log, on_complete, session_ctx) end end - if #rough_diff_blocks == 0 then return false, "No diff blocks found" end + if #rough_diff_blocks == 0 then + Utils.debug("diff", opts.diff) + return false, "No diff blocks found" + end local bufnr, err = Helpers.get_bufnr(abs_path) if err then return false, err end