-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(filter): correctly use uv.cwd
when opts.cwd=true
#757
Conversation
|
Oh then maybe it should be PS: I was confused about |
The actual issue was because of |
I don't think that fixed it. I just pulled and can still see the |
Right, I only fixed the path issue. Will fix the filtering |
I think it should be like |
Filter check also fixed now |
Can you check if this fixes it for what you were testing? |
No, it doesn't. Is what I suggested above |
What is your setup? What options do you set and what do you want to achieve / is wrong? |
Ok @folke I think this all might as well not have been needed in the end. I reverted to 3a3e795 before you made all these changes, because I wanted to check something. The problem lies in the LazyVim configuration i think. When you type Sorry about this, should have done more diligent investigation. |
No worries, but so with the latest changes in snacks, that LazyVim keymap also works as expected right? |
Yes, even the LazyVim keymap works as expected now. Thank you 😄 |
I'm sorry again. But it doesn't. I had changed the mapping to Really sorry about my hastiness... |
And just for completeness this is my whole picker personal configuration picker = {
win = {
input = {
keys = {
["<Esc>"] = { "close", mode = { "n", "i" } },
},
},
},
formatters = {
file = {
filename_first = true,
},
},
sources = {
smart = {
filter = {
paths = {
[vim.fn.stdpath("data")] = false,
[vim.fn.stdpath("cache")] = false,
[vim.fn.stdpath("state")] = false,
},
},
},
projects = {
win = {
input = {
keys = {
["<c-g>"] = { "live_grep", mode = { "i", "n" } },
},
},
},
actions = {
live_grep = function(_, item)
Snacks.picker.pick("grep", {
cwd = item.file,
})
end,
},
confirm = function(_, item)
Snacks.picker.pick("files", {
cwd = item.dir,
})
end,
},
-- Credit https://github.com/folke/snacks.nvim/issues/532#issuecomment-2609303872
files_with_symbols = {
multi = { "files", "lsp_symbols" },
filter = {
---@param p snacks.Picker
---@param filter snacks.picker.Filter
transform = function(p, filter)
local symbol_pattern = filter.pattern:match("^.-@(.*)$")
local line_nr_pattern = filter.pattern:match("^.-:(%d*)$")
local search_pattern = filter.pattern:match("^.-#(.*)$")
local pattern = symbol_pattern or line_nr_pattern or search_pattern
if pattern then
local item = p:current()
if item and item.file then
filter.meta.buf = vim.fn.bufadd(item.file)
end
end
if not filter.meta.buf then
filter.source_id = 1
return
end
if symbol_pattern then
filter.pattern = symbol_pattern
filter.current_buf = filter.meta.buf
filter.source_id = 2
return
end
if line_nr_pattern then
filter.pattern = filter.pattern:gsub(":%d*$", "")
filter.current_buf = filter.meta.buf
filter.source_id = 1
local item = p:current()
if item then
item.pos = { tonumber(line_nr_pattern) or 1, 0 }
p.preview:loc()
end
return
end
if search_pattern then
filter.pattern = filter.pattern:gsub("#.*$", "")
filter.current_buf = filter.meta.buf
filter.source_id = 1
if search_pattern == "" then
return
end
local item = p:current()
vim.api.nvim_buf_call(p.preview.win.buf, function()
vim.api.nvim_win_set_cursor(0, { 1, 0 })
local search = vim.fn.searchpos(search_pattern, "cw")
if search[1] > 0 then
vim.cmd("/" .. search_pattern)
vim.api.nvim_win_set_cursor(0, { search[1], search[2] })
item.pos = { search[1], search[2] }
end
end)
return
end
end,
},
win = {
input = {
keys = {
["<c-n>"] = { "next_result", mode = { "i", "n" } },
["<esc>"] = { "close", mode = { "i", "n" } },
},
},
},
actions = {
close = function(p, _)
vim.cmd("noh")
p:close()
end,
next_result = function(p, _)
local filter = p:filter()
local pattern = filter.pattern
local search_pattern = pattern:match("^.-#(.*)$")
if search_pattern and search_pattern ~= "" then
local item = p:current()
vim.api.nvim_buf_call(p.preview.win.buf, function()
local search = vim.fn.searchpos(search_pattern, "cw")
if search[1] > 0 then
vim.cmd("/" .. search_pattern)
vim.api.nvim_win_set_cursor(0, { search[1], search[2] })
item.pos = { search[1], search[2] }
end
end)
return
end
end,
},
},
lsp_symbols = {
layout = {
preview = "main",
preset = "ivy",
},
},
},
}, But I don't see anything that could cause such behavior. |
Right, that's because of root dir being passed as cwd. |
Ohhh, I see. That's why when I PS: I tested locally and it works, but |
Probbaly better to use the correct Snacks picker. No need to go through LazyVim.pick for this I guess? |
Feel free to create a PR :) |
Description
When
opts.cwd=true
the value ofuv.cwd
should be used to setself.cwd
.Related Issue(s)
Fixes #754
Screenshots