fix: add shim for vim.lsp.util._str_byteindex() (#3338)
Will be removed in Nvim 0.11: https://github.com/neovim/neovim/pull/30915
This commit is contained in:
@@ -105,7 +105,7 @@ end
|
|||||||
---@return lsp.Location
|
---@return lsp.Location
|
||||||
local function item_to_location(item, offset_encoding)
|
local function item_to_location(item, offset_encoding)
|
||||||
local line = item.lnum - 1
|
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
|
local uri
|
||||||
if utils.is_uri(item.filename) then
|
if utils.is_uri(item.filename) then
|
||||||
uri = item.filename
|
uri = item.filename
|
||||||
|
|||||||
@@ -17,6 +17,18 @@ local utils = {}
|
|||||||
|
|
||||||
utils.iswin = vim.loop.os_uname().sysname == "Windows_NT"
|
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
|
--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
|
utils.islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist
|
||||||
local flatten = function(t)
|
local flatten = function(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user