Skip to content

Commit

Permalink
fix: try to fix suggestions (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Feb 7, 2025
1 parent e8b0f33 commit faa6728
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua/avante/suggestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,13 @@ L5: pass
local cursor_row, cursor_col = Utils.get_cursor_pos()
if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end
-- Clean up markdown code blocks
full_response = Utils.trim_think_content(full_response)
full_response = full_response:gsub("^```%w*\n(.-)\n```$", "%1")
full_response = full_response:gsub("(.-)\n```\n?$", "%1")
-- Remove everything before the first '[' to ensure we get just the JSON array
full_response = full_response:gsub("^.-(%[.*)", "%1")
-- Remove everything after the last ']' to ensure we get just the JSON array
full_response = full_response:gsub("(.*%]).-$", "%1")
local ok, suggestions_list = pcall(vim.json.decode, full_response)
if not ok then
Utils.error("Error while decoding suggestions: " .. full_response, { once = true, title = "Avante" })
Expand All @@ -167,6 +170,9 @@ L5: pass
Utils.info("No suggestions found", { once = true, title = "Avante" })
return
end
if #suggestions_list ~= 0 and not vim.islist(suggestions_list[1]) then
suggestions_list = { suggestions_list }
end
local current_lines = Utils.get_buf_lines(0, -1, bufnr)
suggestions_list = vim
.iter(suggestions_list)
Expand Down

0 comments on commit faa6728

Please sign in to comment.