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

Commit 4011f4a

Browse files
authored
Fix inlay_hints callback by using new handler signature (#29)
* Fix inlay_hints callback by using new handler signature This commit made a breaking change to the handler signature: neovim/neovim@df17d78 This commit fixes inlay hints by changing the signature of the callback to the new signature. * Make it backwards compatible
1 parent 379a935 commit 4011f4a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lua/lsp_extensions/inlay_hints.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ interface InlayHint {
2727
```
2828
--]]
2929

30+
local util = require('lsp_extensions.util')
31+
3032
local inlay_hints = {}
3133

3234
local inlay_hints_ns = vim.api.nvim_create_namespace("lsp_extensions.inlay_hints")
@@ -51,7 +53,7 @@ inlay_hints.get_callback = function(opts)
5153
local only_current_line = opts.only_current_line
5254
if only_current_line == nil then only_current_line = false end
5355

54-
return function(err, _, result, _, bufnr)
56+
return util.mk_handler(function(err, result, ctx, _)
5557
-- I'm pretty sure this only happens for unsupported items.
5658
if err or type(result) == 'number' then
5759
return
@@ -61,7 +63,7 @@ inlay_hints.get_callback = function(opts)
6163
return
6264
end
6365

64-
vim.api.nvim_buf_clear_namespace(bufnr, inlay_hints_ns, 0, -1)
66+
vim.api.nvim_buf_clear_namespace(ctx.bufnr, inlay_hints_ns, 0, -1)
6567

6668
local hint_store = {}
6769

@@ -86,7 +88,7 @@ inlay_hints.get_callback = function(opts)
8688

8789
if aligned then
8890
longest_line = math.max(longest_line,
89-
#vim.api.nvim_buf_get_lines(bufnr, finish, finish + 1, false)[1])
91+
#vim.api.nvim_buf_get_lines(ctx.bufnr, finish, finish + 1, false)[1])
9092
end
9193
end
9294
end
@@ -96,18 +98,18 @@ inlay_hints.get_callback = function(opts)
9698

9799
-- Check for any existing / more important virtual text on the line.
98100
-- TODO: Figure out how stackable virtual text works? What happens if there is more than one??
99-
local existing_virt_text = vim.api.nvim_buf_get_extmarks(bufnr, inlay_hints_ns, {end_line, 0},
101+
local existing_virt_text = vim.api.nvim_buf_get_extmarks(ctx.bufnr, inlay_hints_ns, {end_line, 0},
100102
{end_line, 0}, {})
101103
if not vim.tbl_isempty(existing_virt_text) then return end
102104

103105
local text
104106
if aligned then
105-
local line_length = #vim.api.nvim_buf_get_lines(bufnr, end_line, end_line + 1, false)[1]
107+
local line_length = #vim.api.nvim_buf_get_lines(ctx.bufnr, end_line, end_line + 1, false)[1]
106108
text = string.format("%s %s", (" "):rep(longest_line - line_length), prefix .. hint.label)
107109
else
108110
text = prefix .. hint.label
109111
end
110-
vim.api.nvim_buf_set_virtual_text(bufnr, inlay_hints_ns, end_line, {{text, highlight}}, {})
112+
vim.api.nvim_buf_set_virtual_text(ctx.bufnr, inlay_hints_ns, end_line, {{text, highlight}}, {})
111113
end
112114

113115
if only_current_line then
@@ -121,7 +123,7 @@ inlay_hints.get_callback = function(opts)
121123
else
122124
for _, hint in pairs(hint_store) do display_virt_text(hint) end
123125
end
124-
end
126+
end)
125127
end
126128

127129
inlay_hints.get_params = function()

0 commit comments

Comments
 (0)