nvim: implement projects picker

This commit is contained in:
Daniel Lundin 2024-12-30 08:02:33 +01:00
parent 461f3a9a46
commit d2044e7747
Signed by: dln
SSH key fingerprint: SHA256:dQy1Xj3UiqJYpKR5ggQ2bxgz4jCH8IF+k3AB8o0kmdI
2 changed files with 90 additions and 49 deletions

View file

@ -127,6 +127,7 @@ vim.keymap.set('n', '<Leader>f', "<cmd>Pick files_root<cr>", opts("Open file pic
vim.keymap.set('n', '<c-p>', "<Leader>f", { remap = true }) vim.keymap.set('n', '<c-p>', "<Leader>f", { remap = true })
vim.keymap.set('n', '<Leader>g', "<cmd>Pick oldfiles<cr>", opts("Open file picker history")) vim.keymap.set('n', '<Leader>g', "<cmd>Pick oldfiles<cr>", opts("Open file picker history"))
vim.keymap.set("n", '<Leader>k', vim.lsp.buf.hover, opts("Show docs for item under cursor")) vim.keymap.set("n", '<Leader>k', vim.lsp.buf.hover, opts("Show docs for item under cursor"))
vim.keymap.set('n', '<Leader>p', "<cmd>Pick projects<cr>", opts("Open projects picker"))
vim.keymap.set('n', '<Leader>q', require('mini.bufremove').delete, opts("Delete buffer")) vim.keymap.set('n', '<Leader>q', require('mini.bufremove').delete, opts("Delete buffer"))
vim.keymap.set('n', '<Leader>s', "<cmd>Pick lsp scope='document_symbol'<cr>", opts("Open symbol picker")) vim.keymap.set('n', '<Leader>s', "<cmd>Pick lsp scope='document_symbol'<cr>", opts("Open symbol picker"))
vim.keymap.set('n', '<Leader>S', "<cmd>Pick lsp scope='workspace_symbol'<cr>", opts("Open workspace symbol picker")) vim.keymap.set('n', '<Leader>S', "<cmd>Pick lsp scope='workspace_symbol'<cr>", opts("Open workspace symbol picker"))

View file

@ -64,6 +64,45 @@ require('mini.pick').setup({
config = picker_win_config, config = picker_win_config,
}, },
}) })
MiniPick.registry.projects = function(local_opts)
local root = vim.fn.expand("~/src")
local command = {
"fd",
"--max-depth=8",
"--one-file-system",
"--unrestricted",
"--full-path",
"/.jj/repo/store/type$|/.git/HEAD$",
root,
}
local postprocess = function(paths)
local result = {}
for _, path in ipairs(paths) do
path = path:gsub("%/.jj/repo/store/type$", "")
path = path:gsub("%/.git/HEAD$", "")
local item = {
path = path,
text = path:gsub("%" .. root .. "/", ""),
}
table.insert(result, item)
end
return result
end
local choose = function(item)
local_opts.cwd = item.path
vim.fn.chdir(item.path)
vim.schedule(function()
MiniPick.builtin.files(local_opts, { source = { cwd = item.path, tool = "rg" } })
end)
end
return MiniPick.builtin.cli({ command = command, postprocess = postprocess }, { source = { choose = choose } })
end
MiniPick.registry.files_root = function(local_opts) MiniPick.registry.files_root = function(local_opts)
local root_patterns = { ".jj", ".git" } local root_patterns = { ".jj", ".git" }
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1]) local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1])
@ -71,6 +110,7 @@ MiniPick.registry.files_root = function(local_opts)
local_opts.tool = "rg" local_opts.tool = "rg"
return MiniPick.builtin.files(local_opts, { source = { cwd = root_dir, tool = "rg" } }) return MiniPick.builtin.files(local_opts, { source = { cwd = root_dir, tool = "rg" } })
end end
MiniPick.registry.grep_live_root = function(local_opts) MiniPick.registry.grep_live_root = function(local_opts)
local root_patterns = { ".jj", ".git" } local root_patterns = { ".jj", ".git" }
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1]) local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, { upward = true })[1])