mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
fix(picker.lsp): backward compat with Neovim 0.95
This commit is contained in:
parent
f24b437228
commit
3df2408713
2 changed files with 17 additions and 2 deletions
|
@ -9,6 +9,8 @@ local M = {}
|
||||||
---@field desc? string
|
---@field desc? string
|
||||||
---@field name? string
|
---@field name? string
|
||||||
|
|
||||||
|
local islist = vim.islist or vim.tbl_islist
|
||||||
|
|
||||||
---@param picker snacks.Picker
|
---@param picker snacks.Picker
|
||||||
function M.get(picker)
|
function M.get(picker)
|
||||||
local ref = Snacks.util.ref(picker)
|
local ref = Snacks.util.ref(picker)
|
||||||
|
@ -71,7 +73,7 @@ function M.resolve(action, picker, name)
|
||||||
picker,
|
picker,
|
||||||
action:gsub("_ ", " ")
|
action:gsub("_ ", " ")
|
||||||
)
|
)
|
||||||
elseif type(action) == "table" and vim.islist(action) then
|
elseif type(action) == "table" and islist(action) then
|
||||||
---@type snacks.picker.Action[]
|
---@type snacks.picker.Action[]
|
||||||
local actions = vim.tbl_map(function(a)
|
local actions = vim.tbl_map(function(a)
|
||||||
return M.resolve(a, picker)
|
return M.resolve(a, picker)
|
||||||
|
|
|
@ -191,6 +191,18 @@ function M.resolve(item)
|
||||||
return item
|
return item
|
||||||
end
|
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")
|
||||||
|
end
|
||||||
|
return vim.str_byteindex(s, index, encoding == "utf-16")
|
||||||
|
end
|
||||||
|
|
||||||
--- Resolves the location of an item to byte positions
|
--- Resolves the location of an item to byte positions
|
||||||
---@param item snacks.picker.Item
|
---@param item snacks.picker.Item
|
||||||
---@param buf? number
|
---@param buf? number
|
||||||
|
@ -198,6 +210,7 @@ function M.resolve_loc(item, buf)
|
||||||
if not item or not item.loc or item.loc.resolved then
|
if not item or not item.loc or item.loc.resolved then
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
-- return vim._str_byteindex(s, index, encoding == 'utf-16')
|
||||||
|
|
||||||
local lines = {} ---@type string[]
|
local lines = {} ---@type string[]
|
||||||
if buf and vim.api.nvim_buf_is_valid(buf) then
|
if buf and vim.api.nvim_buf_is_valid(buf) then
|
||||||
|
@ -208,7 +221,7 @@ function M.resolve_loc(item, buf)
|
||||||
|
|
||||||
---@param pos lsp.Position?
|
---@param pos lsp.Position?
|
||||||
local function resolve(pos)
|
local function resolve(pos)
|
||||||
return pos and { pos.line + 1, vim.str_byteindex(lines[pos.line + 1], item.loc.encoding, pos.character) } or nil
|
return pos and { pos.line + 1, M.str_byteindex(lines[pos.line + 1], pos.character, item.loc.encoding) } or nil
|
||||||
end
|
end
|
||||||
item.pos = resolve(item.loc.range["start"])
|
item.pos = resolve(item.loc.range["start"])
|
||||||
item.end_pos = resolve(item.loc.range["end"]) or item.end_pos
|
item.end_pos = resolve(item.loc.range["end"]) or item.end_pos
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue