fix: remove trailing spaces each line when editing files (#2612)
This commit is contained in:
@@ -163,7 +163,8 @@ function M.func(input, opts)
|
||||
elseif is_searching then
|
||||
table.insert(current_old_lines, line)
|
||||
elseif is_replacing then
|
||||
table.insert(current_new_lines, line)
|
||||
-- Remove trailing spaces from each line before adding to new_lines
|
||||
table.insert(current_new_lines, (line:gsub("%s+$", "")))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -56,6 +56,11 @@ M.returns = {
|
||||
---@type AvanteLLMToolFunc<{ path: string, old_str: string, new_str: string }>
|
||||
function M.func(input, opts)
|
||||
local replace_in_file = require("avante.llm_tools.replace_in_file")
|
||||
local Utils = require("avante.utils")
|
||||
|
||||
-- Remove trailing spaces from the new string
|
||||
input.new_str = Utils.remove_trailing_spaces(input.new_str)
|
||||
|
||||
local diff = "------- SEARCH\n" .. input.old_str .. "\n=======\n" .. input.new_str
|
||||
if not opts.streaming then diff = diff .. "\n+++++++ REPLACE" end
|
||||
local new_input = {
|
||||
|
||||
@@ -70,6 +70,8 @@ function M.func(input, opts)
|
||||
Utils.debug("Trimming escapes from content")
|
||||
input.the_content = Utils.trim_escapes(input.the_content)
|
||||
end
|
||||
-- Remove trailing spaces from each line
|
||||
input.the_content = Utils.remove_trailing_spaces(input.the_content)
|
||||
local old_lines = Utils.read_file_from_buf_or_disk(abs_path)
|
||||
local old_content = table.concat(old_lines or {}, "\n")
|
||||
local str_replace = require("avante.llm_tools.str_replace")
|
||||
|
||||
Reference in New Issue
Block a user