Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Commit

Permalink
fix(inlay hints): guard against unloaded buffer and nonexistent lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Alvarez committed Nov 21, 2021
1 parent 4405c1a commit 6814f3b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lua/nvim-lsp-ts-utils/inlay-hints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ end

local function handler(err, result, ctx)
if not err and result and M.state.enabled then
hide(ctx.bufnr)
local bufnr = ctx.bufnr
if not vim.api.nvim_buf_is_loaded(bufnr) then
return
end

hide(bufnr)

local hints = result.inlayHints or {}
local parsed = {}

for _, value in ipairs(hints) do
local pos = value.position
local line_str = tostring(pos.line)
Expand All @@ -42,14 +46,17 @@ local function handler(err, result, ctx)
end
end

local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
for key, value in pairs(parsed) do
local line = tonumber(key)
for _, hint in ipairs(value) do
vim.api.nvim_buf_set_extmark(ctx.bufnr, M.state.ns, line, -1, {
virt_text_pos = "eol",
virt_text = { { hint.text, o.get().inlay_hints_highlight } },
hl_mode = "combine",
})
if lines[line + 1] then
for _, hint in ipairs(value) do
vim.api.nvim_buf_set_extmark(ctx.bufnr, M.state.ns, line, -1, {
virt_text_pos = "eol",
virt_text = { { hint.text, o.get().inlay_hints_highlight } },
hl_mode = "combine",
})
end
end
end
end
Expand Down

0 comments on commit 6814f3b

Please sign in to comment.