From faa6728d4b85e0001b7fda5f30115982e957f4bb Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 7 Feb 2025 16:26:35 +0800 Subject: [PATCH] fix: try to fix suggestions (#1209) --- lua/avante/suggestion.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/avante/suggestion.lua b/lua/avante/suggestion.lua index 2218b6c..37c521b 100644 --- a/lua/avante/suggestion.lua +++ b/lua/avante/suggestion.lua @@ -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)