From f226df8348bdfa463cba88f7f979a76193d34c43 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 19 Mar 2025 14:42:35 +0800 Subject: [PATCH] fix: read latest content (#1643) --- lua/avante/llm_tools.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/avante/llm_tools.lua b/lua/avante/llm_tools.lua index 4126df3..86786d5 100644 --- a/lua/avante/llm_tools.lua +++ b/lua/avante/llm_tools.lua @@ -179,8 +179,8 @@ function M.read_file(opts, on_log) if on_log then on_log("path: " .. abs_path) end local file = io.open(abs_path, "r") if not file then return "", "file not found: " .. abs_path end - local content = file:read("*a") - file:close() + local lines = Utils.read_file_from_buf_or_disk(abs_path) + local content = lines and table.concat(lines, "\n") or "" return content, nil end @@ -205,8 +205,8 @@ function M.str_replace_editor(opts, on_log, on_complete) if not Path:new(abs_path):is_file() then return false, "Path is not a file: " .. abs_path end local file = io.open(abs_path, "r") if not file then return false, "file not found: " .. abs_path end - local content = file:read("*a") - file:close() + local lines = Utils.read_file_from_buf_or_disk(abs_path) + local content = lines and table.concat(lines, "\n") or "" on_complete(content, nil) return end