Skip to content

Commit

Permalink
bug: make json decode save
Browse files Browse the repository at this point in the history
fix #15
  • Loading branch information
lukas-reineke committed Nov 30, 2021
1 parent 68475bb commit db55bea
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lua/cmp-rg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ source.complete = function(self, request, callback)
if event == "stdout" then
for _, entry in ipairs(data) do
if entry ~= "" then
local result = vim.fn.json_decode(entry)
if result.type == "context" then
local ok, result = pcall(vim.fn.json_decode, entry)
if not ok or result.type == "end" then
context = {}
documentation_to_add = 0
elseif result.type == "context" then
local documentation = result.data.lines.text:gsub("\n", "")
table.insert(context, documentation)
if documentation_to_add > 0 then
Expand Down Expand Up @@ -65,8 +68,6 @@ source.complete = function(self, request, callback)
documentation_to_add = context_after
seen[label] = true
end
elseif result.type == "end" then
context = {}
end
end
end
Expand Down

0 comments on commit db55bea

Please sign in to comment.