mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(picker.lsp): fixed vim.str_byteindex capability check. Closes #2389
This commit is contained in:
parent
40774ae6ca
commit
46917d0629
1 changed files with 12 additions and 6 deletions
|
|
@ -3,6 +3,8 @@ local M = {}
|
|||
|
||||
local uv = vim.uv or vim.loop
|
||||
|
||||
local str_byteindex_new = pcall(vim.str_byteindex, "aa", "utf-8", 1)
|
||||
|
||||
---@param item snacks.picker.Item
|
||||
---@return string?
|
||||
function M.path(item)
|
||||
|
|
@ -324,13 +326,17 @@ end
|
|||
---@param s string
|
||||
---@param index number
|
||||
---@param encoding string
|
||||
function M.str_byteindex(s, index, encoding)
|
||||
if vim.lsp.util._str_byteindex_enc then
|
||||
return vim.lsp.util._str_byteindex_enc(s, index, encoding)
|
||||
elseif vim._str_byteindex then
|
||||
return vim._str_byteindex(s, index, encoding == "utf-16")
|
||||
---@param strict_indexing? boolean
|
||||
function M.str_byteindex(s, index, encoding, strict_indexing)
|
||||
if str_byteindex_new then
|
||||
return vim.str_byteindex(s, encoding, index, strict_indexing)
|
||||
elseif vim.str_byteindex then
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
return vim.str_byteindex(s, index, encoding == "utf-16")
|
||||
elseif vim.lsp.util._str_byteindex then
|
||||
return vim.lsp.util._str_byteindex(s, index, encoding)
|
||||
end
|
||||
return vim.str_byteindex(s, index, encoding == "utf-16")
|
||||
error("No str_byteindex function available")
|
||||
end
|
||||
|
||||
--- Resolves the location of an item to byte positions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue