Skip to content

Commit

Permalink
fix: add shim for vim.lsp.util._str_byteindex() (#3338)
Browse files Browse the repository at this point in the history
Will be removed in Nvim 0.11: neovim/neovim#30915
  • Loading branch information
tris203 authored Oct 26, 2024
1 parent df534c3 commit 37dc923
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ end
---@return lsp.Location
local function item_to_location(item, offset_encoding)
local line = item.lnum - 1
local character = vim.lsp.util._str_utfindex_enc(item.text, item.col, offset_encoding) - 1
local character = utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1
local uri
if utils.is_uri(item.filename) then
uri = item.filename
Expand Down
12 changes: 12 additions & 0 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ local utils = {}

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

---@param s string
---@param i number
---@param encoding "utf-8" | "utf-16" | "utf-32"
---@return integer
utils.str_byteindex = function(s, i, encoding)
if vim.fn.has "nvim-0.11" == 1 then
return vim.str_byteindex(s, encoding, i, false)
else
return vim.lsp.util._str_byteindex_enc(s, i, encoding)
end
end

--TODO(clason): Remove when dropping support for Nvim 0.9
utils.islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist
local flatten = function(t)
Expand Down

0 comments on commit 37dc923

Please sign in to comment.