Replies: 1 comment
-
So, looking closer at the doc I realized that it is already possible to do what I described using the --- @param picker snacks.Picker
local function find_current_reference(picker)
local items = picker:items()
local filter = picker.finder and picker.finder.filter
if not filter then
return
end
-- Get the source buffer and window
local bufnr = filter.current_buf
local win = filter.current_win
-- Get the cursor position from the original window
local cursor_pos = vim.api.nvim_win_get_cursor(win)
local cursor_row, cursor_col = cursor_pos[1], cursor_pos[2]
local filename = vim.api.nvim_buf_get_name(bufnr)
-- Find the item that matches the current position
for i, item in ipairs(items) do
if item.file and item.pos then
local item_filename = item.file
-- Check if the file matches
if item.buf == bufnr or item_filename == filename then
local start_line, start_col = item.pos[1], item.pos[2]
local end_line = item.end_pos and item.end_pos[1] or start_line
local end_col = item.end_pos and item.end_pos[2] or (start_col + 1)
-- Check if cursor is within the range
if
(cursor_row == start_line and cursor_col >= start_col)
or (cursor_row == end_line and cursor_col <= end_col)
or (cursor_row > start_line and cursor_row < end_line)
then
picker.list:view(i)
Snacks.picker.actions.list_scroll_center(picker)
return
end
end
end
end
end
Snacks.picker.lsp_references({
focus = "list",
include_current = true,
on_show = find_current_reference,
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be nice if we could specify what item we want focused by default when opening a picker. For example, instead of doing
Snacks.picker.lsp_references({ focus = "list" })
, we could doSnacks.picker.lsp_references({ focus = "current" })
which would automatically focus the current reference in the list. It's easy to get lost when there are many references, and this would allow to quickly jump to neighboring references in the same file and make navigation much smoother.This would also be very useful to navigate lsp symbols in a big file. For example:
Snacks.picker.lsp_symbols({ focus = "nearest" })
could focus the nearest item on the list from our current position in the file and allow us to kind of quickly "zoom out", locate ourselves, and move around.To make this a more generic feature, maybe
focus
could instead accept a function that takes in the list of items and returns the index for the item that should be focused.Beta Was this translation helpful? Give feedback.
All reactions