From 1dc195d9ef33c6a3d42ee7566ffc0e734eaf3195 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 17 Jul 2025 19:48:37 +0800 Subject: [PATCH] fix: edit_file cannot find old str --- lua/avante/llm_tools/edit_file.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/avante/llm_tools/edit_file.lua b/lua/avante/llm_tools/edit_file.lua index 8534431..826835d 100644 --- a/lua/avante/llm_tools/edit_file.lua +++ b/lua/avante/llm_tools/edit_file.lua @@ -59,18 +59,21 @@ M.func = vim.schedule_wrap(function(input, opts) if not provider then return false, "morph provider not found" end if not provider.is_env_set() then return false, "morph provider not set" end - local original_code local ok, lines = pcall(Utils.read_file_from_buf_or_disk, input.target_file) if not ok then local f = io.open(input.target_file, "r") if f then - original_code = f:read("*all") + local original_code = f:read("*all") f:close() + lines = vim.split(original_code, "\n") end - else - original_code = table.concat(lines or {}, "\n") end + if lines and #lines > 0 then + if lines[#lines] == "" then lines = vim.list_slice(lines, 0, #lines - 1) end + end + local original_code = table.concat(lines or {}, "\n") + local provider_conf = Providers.parse_config(provider) local body = {