Skip to content

Commit a093f37

Browse files
committed
fix(inlay_hints): safely call nvim_buf_get_lines with pcall
1 parent 71d2cf6 commit a093f37

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lua/rust-tools/inlay_hints.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,27 @@ local function parse_hints(result, bufnr)
124124
if type(result) ~= "table" then
125125
return {}
126126
end
127+
127128
for _, value in pairs(result) do
128129
local range = value.position
129130
local line = value.position.line
130131
local label = value.label
131132
local kind = value.kind
132133

133-
local function add_line()
134-
if map[line] ~= nil then
135-
table.insert(map[line], { label = label, kind = kind, range = range })
136-
else
137-
map[line] = { { label = label, kind = kind, range = range } }
138-
end
134+
local status_ok, lines = pcall(vim.api.nvim_buf_get_lines, bufnr, line, line + 1, true)
135+
136+
if not status_ok then
137+
break
139138
end
140139

141-
local line_len =
142-
string.len(vim.api.nvim_buf_get_lines(bufnr, line, line + 1, true)[1])
140+
local line_len = string.len(lines[1])
143141
max_line_len = math.max(max_line_len, line_len)
144142

145-
add_line()
143+
if map[line] ~= nil then
144+
table.insert(map[line], { label = label, kind = kind, range = range })
145+
else
146+
map[line] = { { label = label, kind = kind, range = range } }
147+
end
146148
end
147149
return map, max_line_len
148150
end

0 commit comments

Comments
 (0)