fix(gemini): check if json can be decoded (#446)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-09-01 18:47:35 -04:00 committed by GitHub
parent 3ccb71d7ef
commit 7912070c6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -140,6 +140,7 @@ M.defaults = {
wrap = true, -- similar to vim.o.wrap wrap = true, -- similar to vim.o.wrap
width = 30, -- default % based on available width in vertical layout width = 30, -- default % based on available width in vertical layout
height = 30, -- default % based on available height in horizontal layout height = 30, -- default % based on available height in horizontal layout
direction = "right", -- "left" | "right"
sidebar_header = { sidebar_header = {
align = "center", -- left, center, right for title align = "center", -- left, center, right for title
rounded = true, rounded = true,

View File

@ -50,9 +50,16 @@ M.parse_message = function(opts)
end end
M.parse_response = function(data_stream, _, opts) M.parse_response = function(data_stream, _, opts)
local json = vim.json.decode(data_stream) local ok, json = pcall(vim.json.decode, data_stream)
if json.candidates and #json.candidates > 0 then if not ok then
opts.on_chunk(json.candidates[1].content.parts[1].text) opts.on_complete(json)
end
if json.candidates then
if #json.candidates > 0 then
opts.on_chunk(json.candidates[1].content.parts[1].text)
elseif json.candidates.finishReason and json.candidates.finishReason == "STOP" then
opts.on_complete(nil)
end
end end
end end

View File

@ -1383,7 +1383,7 @@ function Sidebar:create_input()
if self:get_layout() == "vertical" then if self:get_layout() == "vertical" then
return "bottom" return "bottom"
end end
return "right" return Config.windows.direction
end end
local get_size = function() local get_size = function()