fix: try to fix suggestions (#1209)

This commit is contained in:
yetone 2025-02-07 16:26:35 +08:00 committed by GitHub
parent e8b0f33f18
commit faa6728d4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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" })
@ -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)