Skip to content

Commit 1a2efaf

Browse files
committed
fix(lsp): handle invalid line positions
1 parent affd249 commit 1a2efaf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lua/trouble/sources/lsp.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ local Util = require("trouble.util")
1010
---@param encoding string utf-8|utf-16|utf-32| defaults to utf-16
1111
---@return integer byte (utf-8) index of `encoding` index `index` in `line`
1212
local function get_line_col(line, index, encoding)
13-
if vim.str_byteindex then
14-
-- FIXME: uses old-style func signature, since there's no way to
15-
-- properly detect if new style is available
16-
return vim.str_byteindex(line, index, encoding == "utf-16")
13+
local function get()
14+
if vim.str_byteindex then
15+
-- FIXME: uses old-style func signature, since there's no way to
16+
-- properly detect if new style is available
17+
return vim.str_byteindex(line, index, encoding == "utf-16")
18+
end
19+
return vim.lsp.util._str_byteindex_enc(line, index, encoding)
1720
end
18-
local ok, ret = pcall(vim.lsp.util._str_byteindex_enc, line, index, encoding)
21+
local ok, ret = pcall(get)
1922
return ok and ret or #line
2023
end
2124

0 commit comments

Comments
 (0)