Skip to content

Commit

Permalink
fix: incorrect filepath (yetone#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Nov 17, 2024
1 parent 3051bfd commit 0b1cd55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
with:
crate: stylua
features: lua54
- run: stylua --version
- run: stylua --check ./lua/ ./plugin/
luacheck:
name: Lint Lua
Expand Down
12 changes: 11 additions & 1 deletion lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -355,14 +362,16 @@ 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"),
lang = lang,
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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lua/avante/templates/planning.avanterules
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -86,7 +86,7 @@ mathweb/flask/app.py

Here are the *SEARCH/REPLACE* blocks:

hello.py
<FILEPATH>hello.py</FILEPATH>
<SEARCH>
</SEARCH>
<REPLACE>
Expand All @@ -96,7 +96,7 @@ def hello():
print("hello")
</REPLACE>

main.py
<FILEPATH>main.py</FILEPATH>
<SEARCH>
def hello():
"print a greeting"
Expand Down
4 changes: 3 additions & 1 deletion lua/avante/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b1cd55

Please sign in to comment.