From 14cfccdba9cff320f78f7de6d8fbd9fff8325f75 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 10 Jul 2025 10:17:48 +0800 Subject: [PATCH] fix: do not use str_replace_editor (#2428) --- lua/avante/llm_tools/replace_in_file.lua | 25 +++++++++++--------- lua/avante/providers/claude.lua | 29 ------------------------ 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/lua/avante/llm_tools/replace_in_file.lua b/lua/avante/llm_tools/replace_in_file.lua index f97b016..f8b7f16 100644 --- a/lua/avante/llm_tools/replace_in_file.lua +++ b/lua/avante/llm_tools/replace_in_file.lua @@ -575,6 +575,7 @@ function M.func(opts, on_log, on_complete, session_ctx) end local function highlight_diff_blocks() + local line_count = vim.api.nvim_buf_line_count(bufnr) vim.api.nvim_buf_clear_namespace(bufnr, NAMESPACE, 0, -1) local base_line_ = 0 local max_col = vim.o.columns @@ -591,17 +592,19 @@ function M.func(opts, on_log, on_complete, session_ctx) :totable() -- local extmark_line = math.max(0, start_line - 2) local end_row = start_line + #diff_block.new_lines - 1 - local delete_extmark_id = vim.api.nvim_buf_set_extmark(bufnr, NAMESPACE, end_row - 1, 0, { - virt_lines = deleted_virt_lines, - hl_eol = true, - hl_mode = "combine", - }) - local incoming_extmark_id = vim.api.nvim_buf_set_extmark(bufnr, NAMESPACE, start_line - 1, 0, { - hl_group = Highlights.INCOMING, - hl_eol = true, - hl_mode = "combine", - end_row = end_row, - }) + local delete_extmark_id = + vim.api.nvim_buf_set_extmark(bufnr, NAMESPACE, math.min(math.max(end_row - 1, 0), line_count - 1), 0, { + virt_lines = deleted_virt_lines, + hl_eol = true, + hl_mode = "combine", + }) + local incoming_extmark_id = + vim.api.nvim_buf_set_extmark(bufnr, NAMESPACE, math.min(math.max(start_line - 1, 0), line_count - 1), 0, { + hl_group = Highlights.INCOMING, + hl_eol = true, + hl_mode = "combine", + end_row = end_row, + }) diff_block.delete_extmark_id = delete_extmark_id diff_block.incoming_extmark_id = incoming_extmark_id end diff --git a/lua/avante/providers/claude.lua b/lua/avante/providers/claude.lua index a21fcd1..abf7ac3 100644 --- a/lua/avante/providers/claude.lua +++ b/lua/avante/providers/claude.lua @@ -1,7 +1,6 @@ local Utils = require("avante.utils") local Clipboard = require("avante.clipboard") local P = require("avante.providers") -local Config = require("avante.config") local HistoryMessage = require("avante.history_message") local JsonParser = require("avante.libs.jsonparser") @@ -363,35 +362,7 @@ function M:parse_curl_args(prompt_opts) local tools = {} if not disable_tools and prompt_opts.tools then for _, tool in ipairs(prompt_opts.tools) do - if Config.mode == "agentic" then - if tool.name == "create_file" then goto continue end - if tool.name == "view" then goto continue end - if tool.name == "str_replace" then goto continue end - if tool.name == "create" then goto continue end - if tool.name == "insert" then goto continue end - if tool.name == "undo_edit" then goto continue end - end table.insert(tools, self:transform_tool(tool)) - ::continue:: - end - end - - if prompt_opts.tools and #prompt_opts.tools > 0 and Config.mode == "agentic" then - if provider_conf.model:match("claude%-sonnet%-4") then - table.insert(tools, { - type = "text_editor_20250429", - name = "str_replace_based_edit_tool", - }) - elseif provider_conf.model:match("claude%-3%-7%-sonnet") then - table.insert(tools, { - type = "text_editor_20250124", - name = "str_replace_editor", - }) - elseif provider_conf.model:match("claude%-3%-5%-sonnet") then - table.insert(tools, { - type = "text_editor_20250124", - name = "str_replace_editor", - }) end end