From a537945573862fc56c69c57f6b4dde0e2ed1a495 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 6 Jun 2025 15:47:31 +0800 Subject: [PATCH] fix: streaming diff debouncing (#2174) --- lua/avante/llm_tools/replace_in_file.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/avante/llm_tools/replace_in_file.lua b/lua/avante/llm_tools/replace_in_file.lua index 2119617..73e6881 100644 --- a/lua/avante/llm_tools/replace_in_file.lua +++ b/lua/avante/llm_tools/replace_in_file.lua @@ -113,16 +113,15 @@ function M.func(opts, on_log, on_complete, session_ctx) local is_streaming = opts.streaming or false + local current_timestamp = os.time() if is_streaming then session_ctx.prev_streaming_diff_timestamp_map = session_ctx.prev_streaming_diff_timestamp_map or {} local prev_streaming_diff_timestamp = session_ctx.prev_streaming_diff_timestamp_map[opts.tool_use_id] - local current_timestamp = os.time() if prev_streaming_diff_timestamp ~= nil then if current_timestamp - prev_streaming_diff_timestamp < 2 then return false, "Diff hasn't changed in the last 2 seconds" end end - session_ctx.prev_streaming_diff_timestamp_map[opts.tool_use_id] = current_timestamp local streaming_diff_lines_count = Utils.count_lines(opts.diff) session_ctx.streaming_diff_lines_count_history = session_ctx.streaming_diff_lines_count_history or {} local prev_streaming_diff_lines_count = session_ctx.streaming_diff_lines_count_history[opts.tool_use_id] @@ -180,6 +179,8 @@ function M.func(opts, on_log, on_complete, session_ctx) return false, "No diff blocks found" end + session_ctx.prev_streaming_diff_timestamp_map[opts.tool_use_id] = current_timestamp + local bufnr, err = Helpers.get_bufnr(abs_path) if err then return false, err end