From c60dc6c316414c2adf5bb61624719d76accab22f Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 14 Feb 2025 12:28:39 +0800 Subject: [PATCH] fix: case insensitive (#1275) --- lua/avante/sidebar.lua | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 8305f9f..02a25d3 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -219,27 +219,19 @@ local function transform_result_content(selected_files, result_content, prev_fil while true do if i > #result_lines then break end local line_content = result_lines[i] - if line_content:match(".+") then - local filepath = line_content:match("(.+)") + if line_content:match("<[Ff][Ii][Ll][Ee][Pp][Aa][Tt][Hh]>.+") then + local filepath = line_content:match("<[Ff][Ii][Ll][Ee][Pp][Aa][Tt][Hh]>(.+)") if filepath then current_filepath = filepath table.insert(transformed_lines, string.format("Filepath: %s", filepath)) goto continue end end - if line_content:match(".+") then - local filepath = line_content:match("(.+)") - if filepath then - current_filepath = filepath - table.insert(transformed_lines, string.format("Filepath: %s", filepath)) - goto continue - end - end - if line_content:match("^%s*") then + if line_content:match("^%s*<[Ss][Ee][Aa][Rr][Cc][Hh]>") then is_searching = true - if not line_content:match("^%s*%s*$") then - local search_start_line = line_content:match("(.+)$") + if not line_content:match("^%s*<[Ss][Ee][Aa][Rr][Cc][Hh]>%s*$") then + local search_start_line = line_content:match("<[Ss][Ee][Aa][Rr][Cc][Hh]>(.+)$") line_content = "" result_lines[i] = line_content if search_start_line and search_start_line ~= "" then table.insert(result_lines, i + 1, search_start_line) end @@ -251,8 +243,7 @@ local function transform_result_content(selected_files, result_content, prev_fil prev_line and prev_filepath and not prev_line:match("Filepath:.+") - and not prev_line:match(".+") - and not prev_line:match(".+") + and not prev_line:match("<[Ff][Ii][Ll][Ee][Pp][Aa][Tt][Hh]>.+") then table.insert(transformed_lines, string.format("Filepath: %s", prev_filepath)) end @@ -260,15 +251,15 @@ local function transform_result_content(selected_files, result_content, prev_fil if next_line and next_line:match("^%s*```%w+$") then i = i + 1 end search_start = i + 1 last_search_tag_start_line = i - elseif line_content:match("%s*$") then + elseif line_content:match("%s*$") then if is_replacing then - result_lines[i] = line_content:gsub("", "") + result_lines[i] = line_content:gsub("", "") goto continue_without_increment end -- Handle case where is a suffix - if not line_content:match("^%s*%s*$") then - local search_end_line = line_content:match("^(.+)") + if not line_content:match("^%s*%s*$") then + local search_end_line = line_content:match("^(.+)") line_content = "" result_lines[i] = line_content if search_end_line and search_end_line ~= "" then @@ -365,10 +356,10 @@ local function transform_result_content(selected_files, result_content, prev_fil string.format("```%s", match_filetype), }) goto continue - elseif line_content:match("^%s*") then + elseif line_content:match("^%s*<[Rr][Ee][Pp][Ll][Aa][Cc][Ee]>") then is_replacing = true - if not line_content:match("^%s*%s*$") then - local replace_first_line = line_content:match("(.+)$") + if not line_content:match("^%s*<[Rr][Ee][Pp][Ll][Aa][Cc][Ee]>%s*$") then + local replace_first_line = line_content:match("<[Rr][Ee][Pp][Ll][Aa][Cc][Ee]>(.+)$") line_content = "" result_lines[i] = line_content if replace_first_line and replace_first_line ~= "" then @@ -379,10 +370,10 @@ local function transform_result_content(selected_files, result_content, prev_fil if next_line and next_line:match("^%s*```%w+$") then i = i + 1 end last_replace_tag_start_line = i goto continue - elseif line_content:match("%s*$") then + elseif line_content:match("%s*$") then -- Handle case where is a suffix - if not line_content:match("^%s*%s*$") then - local replace_end_line = line_content:match("^(.+)") + if not line_content:match("^%s*%s*$") then + local replace_end_line = line_content:match("^(.+)") line_content = "" result_lines[i] = line_content if replace_end_line and replace_end_line ~= "" then