feat(planning): supports insert code after line (#605)

This commit is contained in:
yetone 2024-09-19 10:17:35 +08:00 committed by GitHub
parent 20a81b891e
commit 8fa2757e1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
@ -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, "=======")
@ -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)