Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error on nvim_buf_get_extmarks #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions lua/hologram/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,28 @@ end
local prev_ids = {}

function hologram.buf_render_images(buf, top, bot)
local exts = vim.api.nvim_buf_get_extmarks(buf,
vim.g.hologram_extmark_ns,
{math.max(top-1, 0), 0},
{bot-2, -1},
{})

local curr_ids = {}
for _, ext in ipairs(exts) do
local id, row, col = unpack(ext)
Image.instances[id]:display(row+1, 0, buf, {})
curr_ids[#curr_ids+1] = id
end
local ok, exts = pcall(vim.api.nvim_buf_get_extmarks, buf,
vim.g.hologram_extmark_ns,
{math.max(top-1, 0), 0},
{bot-2, -1},
{})
if ok then
local curr_ids = {}
for _, ext in ipairs(exts) do
local id, row, col = unpack(ext)
Image.instances[id]:display(row+1, 0, buf, {})
curr_ids[#curr_ids+1] = id
end

if prev_ids[buf] ~= nil then
for _, id in ipairs(prev_ids[buf]) do
if not vim.tbl_contains(curr_ids, id) then
Image.instances[id]:delete(buf, {})
if prev_ids[buf] ~= nil then
for _, id in ipairs(prev_ids[buf]) do
if not vim.tbl_contains(curr_ids, id) then
Image.instances[id]:delete(buf, {})
end
end
end
prev_ids[buf] = curr_ids
end
prev_ids[buf] = curr_ids
end

function hologram.buf_generate_images(buf, top, bot)
Expand Down