Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect filepath #865

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: incorrect filepath
  • Loading branch information
yetone committed Nov 17, 2024
commit 2cd0403f79e99d3097b70442f7a7f249a703ffbe
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