From 07c1d707da365c23e019f79b533cd7004e590d6b Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 30 Aug 2024 15:40:40 +0800 Subject: [PATCH] fix: indentation issue in copilot model and openai model (#393) --- lua/avante/sidebar.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 2bc9dcd..532b87f 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -262,14 +262,24 @@ local function get_conflict_content(content, snippets) current_line = current_line + 1 end + local need_prepend_indentation = false + local original_start_line_indentation = Utils.get_indentation(lines[start_line] or "") + table.insert(result, "<<<<<<< HEAD") for i = start_line, end_line do table.insert(result, lines[i]) end table.insert(result, "=======") - for _, line in ipairs(vim.split(snippet.content, "\n")) do + for idx, line in ipairs(vim.split(snippet.content, "\n")) do line = line:gsub("^L%d+: ", "") + if idx == 1 then + local indentation = Utils.get_indentation(line) + need_prepend_indentation = indentation ~= original_start_line_indentation + end + if need_prepend_indentation then + line = original_start_line_indentation .. line + end table.insert(result, line) end