mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
feat(picker.lsp): use existing buffers for preview when opened
This commit is contained in:
parent
6d3c135235
commit
d4e63531c9
1 changed files with 17 additions and 1 deletions
|
@ -168,6 +168,19 @@ function M.fix_locs(locs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.bufmap()
|
||||||
|
local bufmap = {} ---@type table<string,number>
|
||||||
|
for _, b in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if vim.bo[b].buflisted and vim.bo[b].buftype == "" and vim.api.nvim_buf_is_loaded(b) then
|
||||||
|
local name = vim.api.nvim_buf_get_name(b)
|
||||||
|
if name ~= "" then
|
||||||
|
bufmap[name] = b
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return bufmap
|
||||||
|
end
|
||||||
|
|
||||||
---@param method string
|
---@param method string
|
||||||
---@param opts snacks.picker.lsp.Config|{context?:lsp.ReferenceContext}
|
---@param opts snacks.picker.lsp.Config|{context?:lsp.ReferenceContext}
|
||||||
---@param filter snacks.picker.Filter
|
---@param filter snacks.picker.Filter
|
||||||
|
@ -177,6 +190,7 @@ function M.get_locations(method, opts, filter)
|
||||||
local fname = vim.api.nvim_buf_get_name(buf)
|
local fname = vim.api.nvim_buf_get_name(buf)
|
||||||
fname = vim.fs.normalize(fname)
|
fname = vim.fs.normalize(fname)
|
||||||
local cursor = vim.api.nvim_win_get_cursor(win)
|
local cursor = vim.api.nvim_win_get_cursor(win)
|
||||||
|
local bufmap = M.bufmap()
|
||||||
|
|
||||||
---@async
|
---@async
|
||||||
---@param cb async fun(item: snacks.picker.finder.Item)
|
---@param cb async fun(item: snacks.picker.finder.Item)
|
||||||
|
@ -218,7 +232,7 @@ function M.get_locations(method, opts, filter)
|
||||||
---@type snacks.picker.finder.Item
|
---@type snacks.picker.finder.Item
|
||||||
local item = {
|
local item = {
|
||||||
text = loc.filename .. " " .. loc.text,
|
text = loc.filename .. " " .. loc.text,
|
||||||
buf = loc.bufnr,
|
buf = bufmap[loc.filename],
|
||||||
file = loc.filename,
|
file = loc.filename,
|
||||||
pos = { loc.lnum, loc.col - 1 },
|
pos = { loc.lnum, loc.col - 1 },
|
||||||
end_pos = loc.end_lnum and loc.end_col and { loc.end_lnum, loc.end_col - 1 } or nil,
|
end_pos = loc.end_lnum and loc.end_col and { loc.end_lnum, loc.end_col - 1 } or nil,
|
||||||
|
@ -341,6 +355,7 @@ function M.symbols(opts, ctx)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local bufmap = M.bufmap()
|
||||||
local filter = opts.filter[vim.bo[buf].filetype]
|
local filter = opts.filter[vim.bo[buf].filetype]
|
||||||
if filter == nil then
|
if filter == nil then
|
||||||
filter = opts.filter.default
|
filter = opts.filter.default
|
||||||
|
@ -370,6 +385,7 @@ function M.symbols(opts, ctx)
|
||||||
})
|
})
|
||||||
for _, item in ipairs(items) do
|
for _, item in ipairs(items) do
|
||||||
item.tree = opts.tree
|
item.tree = opts.tree
|
||||||
|
item.buf = bufmap[item.file]
|
||||||
---@diagnostic disable-next-line: await-in-sync
|
---@diagnostic disable-next-line: await-in-sync
|
||||||
cb(item)
|
cb(item)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue