fix: fuzzy match (#2221)

This commit is contained in:
yetone
2025-06-13 16:46:55 +08:00
committed by GitHub
parent f766b42d85
commit fdf4716ec0
4 changed files with 99 additions and 105 deletions

View File

@@ -199,21 +199,7 @@ function M.func(opts, on_log, on_complete, session_ctx)
local function complete_rough_diff_block(rough_diff_block)
local old_lines = rough_diff_block.old_lines
local new_lines = rough_diff_block.new_lines
local start_line, end_line
for i = 1, #original_lines - #old_lines + 1 do
local match = true
for j = 1, #old_lines do
if Utils.remove_indentation(original_lines[i + j - 1]) ~= Utils.remove_indentation(old_lines[j]) then
match = false
break
end
end
if match then
start_line = i
end_line = i + #old_lines - 1
break
end
end
local start_line, end_line = Utils.fuzzy_match(original_lines, old_lines)
if start_line == nil or end_line == nil then
local old_string = table.concat(old_lines, "\n")
return "Failed to find the old string:\n" .. old_string