Skip to content

Commit 37dc923

Browse files
authored
fix: add shim for vim.lsp.util._str_byteindex() (#3338)
Will be removed in Nvim 0.11: neovim/neovim#30915
1 parent df534c3 commit 37dc923

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lua/telescope/builtin/__lsp.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ end
105105
---@return lsp.Location
106106
local function item_to_location(item, offset_encoding)
107107
local line = item.lnum - 1
108-
local character = vim.lsp.util._str_utfindex_enc(item.text, item.col, offset_encoding) - 1
108+
local character = utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1
109109
local uri
110110
if utils.is_uri(item.filename) then
111111
uri = item.filename

lua/telescope/utils.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ local utils = {}
1717

1818
utils.iswin = vim.loop.os_uname().sysname == "Windows_NT"
1919

20+
---@param s string
21+
---@param i number
22+
---@param encoding "utf-8" | "utf-16" | "utf-32"
23+
---@return integer
24+
utils.str_byteindex = function(s, i, encoding)
25+
if vim.fn.has "nvim-0.11" == 1 then
26+
return vim.str_byteindex(s, encoding, i, false)
27+
else
28+
return vim.lsp.util._str_byteindex_enc(s, i, encoding)
29+
end
30+
end
31+
2032
--TODO(clason): Remove when dropping support for Nvim 0.9
2133
utils.islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist
2234
local flatten = function(t)

0 commit comments

Comments
 (0)