Handle backticks before decoding JSON (#683)

* feat: Clean up full_response before JSON decoding

* fix: make backtick matching more accurate
This commit is contained in:
Changmin Choi 2024-10-08 17:13:56 +09:00 committed by GitHub
parent 2a72dfa711
commit 08bed9e256
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -85,6 +85,7 @@ function Suggestion:suggest()
vim.schedule(function() vim.schedule(function()
local cursor_row, cursor_col = Utils.get_cursor_pos() local cursor_row, cursor_col = Utils.get_cursor_pos()
if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end
full_response = full_response:gsub("^```%w*\n(.-)\n```$", "%1")
local ok, suggestions = pcall(vim.json.decode, full_response) local ok, suggestions = pcall(vim.json.decode, full_response)
if not ok then if not ok then
Utils.error("Error while decoding suggestions: " .. full_response, { once = true, title = "Avante" }) Utils.error("Error while decoding suggestions: " .. full_response, { once = true, title = "Avante" })