fix: incorrect filepath (#865)

This commit is contained in:
yetone 2024-11-18 02:55:44 +08:00 committed by GitHub
parent 3051bfdf24
commit 0b1cd5509e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 6 deletions

View File

@ -19,6 +19,7 @@ jobs:
with:
crate: stylua
features: lua54
- run: stylua --version
- run: stylua --check ./lua/ ./plugin/
luacheck:
name: Lint Lua

View File

@ -173,6 +173,13 @@ local function transform_result_content(original_content, result_content, code_l
local i = 1
while i <= #result_lines do
local line_content = result_lines[i]
if line_content:match("<FILEPATH>.+</FILEPATH>") then
local filepath = line_content:match("<FILEPATH>(.+)</FILEPATH>")
if filepath then
table.insert(transformed_lines, string.format("Filepath: %s", filepath))
goto continue
end
end
if line_content == "<SEARCH>" then
is_searching = true
local next_line = result_lines[i + 1]
@ -355,6 +362,8 @@ local function extract_code_snippets_map(response_content)
if line:match("^%s*```") then
if in_code_block then
if start_line ~= nil and end_line ~= nil then
local filepath = lines[start_line_in_response_buf - 2]
if filepath:match("^[Ff]ilepath:") then filepath = filepath:match("^[Ff]ilepath:%s*(.+)") end
local snippet = {
range = { start_line, end_line },
content = table.concat(current_snippet, "\n"),
@ -362,7 +371,7 @@ local function extract_code_snippets_map(response_content)
explanation = explanation,
start_line_in_response_buf = start_line_in_response_buf,
end_line_in_response_buf = idx,
filepath = lines[start_line_in_response_buf - 2],
filepath = filepath,
}
table.insert(snippets, snippet)
end
@ -558,6 +567,7 @@ function Sidebar:apply(current_cursor)
end
vim.defer_fn(function()
api.nvim_set_current_win(self.code.winid)
for filepath, snippets in pairs(selected_snippets_map) do
local bufnr = Utils.get_or_create_buffer_with_filepath(filepath)
insert_conflict_contents(bufnr, snippets)

View File

@ -45,7 +45,7 @@ ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!
Here are the *SEARCH/REPLACE* blocks:
mathweb/flask/app.py
<FILEPATH>mathweb/flask/app.py</FILEPATH>
<SEARCH>
from flask import Flask
</SEARCH>
@ -68,7 +68,7 @@ def factorial(n):
<REPLACE>
</REPLACE>
mathweb/flask/app.py
<FILEPATH>mathweb/flask/app.py</FILEPATH>
<SEARCH>
return str(factorial(n))
</SEARCH>
@ -86,7 +86,7 @@ mathweb/flask/app.py
Here are the *SEARCH/REPLACE* blocks:
hello.py
<FILEPATH>hello.py</FILEPATH>
<SEARCH>
</SEARCH>
<REPLACE>
@ -96,7 +96,7 @@ def hello():
print("hello")
</REPLACE>
main.py
<FILEPATH>main.py</FILEPATH>
<SEARCH>
def hello():
"print a greeting"

View File

@ -272,7 +272,9 @@ end
---@param msg string|string[]
---@param opts? LazyNotifyOpts
function M.notify(msg, opts)
if vim.in_fast_event() then return vim.schedule(function() M.notify(msg, opts) end) end
if vim.in_fast_event() then
return vim.schedule(function() M.notify(msg, opts) end)
end
opts = opts or {}
if type(msg) == "table" then