Skip to content

Commit

Permalink
feat(planning): supports insert code after line (yetone#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Sep 19, 2024
1 parent 20a81b8 commit 8fa2757
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ local function extract_code_snippets(code_content, response_content)
if start_line_str ~= nil then
start_line = tonumber(start_line_str)
end_line = tonumber(start_line_str)
else
start_line_str = line:match("[Aa]fter%s+[Ll]ine:?%s*(%d+)")
if start_line_str ~= nil then
start_line = tonumber(start_line_str) + 1
end_line = tonumber(start_line_str) + 1
end
end
end
if line:match("^%s*```") then
Expand Down Expand Up @@ -435,8 +441,10 @@ local function insert_conflict_contents(bufnr, snippets)

local result = {}
table.insert(result, "<<<<<<< HEAD")
for i = start_line, end_line do
table.insert(result, lines[i])
if start_line ~= end_line then
for i = start_line, end_line do
table.insert(result, lines[i])
end
end
table.insert(result, "=======")

Expand All @@ -452,6 +460,8 @@ local function insert_conflict_contents(bufnr, snippets)
table.insert(result, line)
end

if start_line == end_line then table.insert(result, lines[start_line]) end

table.insert(result, ">>>>>>> Snippet")

api.nvim_buf_set_lines(bufnr, offset + start_line - 1, offset + end_line, false, result)
Expand Down

0 comments on commit 8fa2757

Please sign in to comment.