feat(pick): move pickers to extras telescope & fzf-lua and include telescope by default

This commit is contained in:
Folke Lemaitre 2024-06-12 14:01:31 +02:00
parent 4b9e4edbb1
commit b2b6ff0738
7 changed files with 309 additions and 266 deletions

View file

@ -32,6 +32,7 @@ local deprecated = {
toggle_diagnostics = { "toggle", "diagnostics" },
toggle_number = { "toggle", "number" },
fg = "ui",
telescope = "pick",
}
setmetatable(M, {
@ -78,8 +79,10 @@ end
---@param extra string
function M.has_extra(extra)
local Config = require("lazyvim.config")
local modname = "lazyvim.plugins.extras." .. extra
return vim.tbl_contains(require("lazy.core.config").spec.modules, modname)
or vim.tbl_contains(Config.json.data.extras, modname)
end
---@param fn fun()

View file

@ -12,14 +12,43 @@ local M = setmetatable({}, {
---@field buf? number
---@field show_untracked? boolean
---@class LazyPicker
---@field name string
---@field open fun(command:string, opts?:lazyvim.util.pick.Opts)
---@field commands table<string, string>
---@type LazyPicker?
M.picker = nil
---@type table<string, string>
M.commands = {
files = "find_files",
}
---@param picker LazyPicker
function M.register(picker)
-- this only happens when using :LazyExtras
-- so allow to get the full spec
if vim.v.vim_did_enter == 1 then
return true
end
if M.picker then
LazyVim.warn(
"`LazyVim.pick`: picker already set to `" .. M.picker.name .. "`,\nignoring new picker `" .. picker.name .. "`"
)
return false
end
M.picker = picker
return true
end
---@param command? string
---@param opts? lazyvim.util.pick.Opts
function M.open(command, opts)
if not M.picker then
return LazyVim.error("LazyVim.pick: picker not set")
end
command = command or "auto"
opts = opts or {}
@ -46,8 +75,8 @@ function M.open(command, opts)
opts.show_untracked = opts.show_untracked ~= false
end
end
command = M.commands[command] or command
M._open(command, opts)
command = M.picker.commands[command] or command
M.picker.open(command, opts)
end
---@param command? string

View file

@ -1,48 +0,0 @@
---@class lazyvim.util.telescope
---@overload fun(builtin:string, opts?:lazyvim.util.pick.Opts)
local M = setmetatable({}, {
__call = function(m, ...)
return m.telescope(...)
end,
})
-- this will return a function that calls telescope.
-- cwd will default to lazyvim.util.get_root
-- for `files`, git_files or find_files will be chosen depending on .git
---@param builtin string
---@param opts? lazyvim.util.pick.Opts
function M.open(builtin, opts)
opts = opts or {}
if opts.cwd and opts.cwd ~= vim.uv.cwd() then
local function open_cwd_dir()
local action_state = require("telescope.actions.state")
local line = action_state.get_current_line()
LazyVim.pick.open(
builtin,
vim.tbl_deep_extend("force", {}, opts or {}, {
root = false,
default_text = line,
})
)
end
---@diagnostic disable-next-line: inject-field
opts.attach_mappings = function(_, map)
-- opts.desc is overridden by telescope, until it's changed there is this fix
map("i", "<a-c>", open_cwd_dir, { desc = "Open cwd Directory" })
return true
end
end
require("telescope.builtin")[builtin](opts)
end
M.telescope = function(...)
LazyVim.deprecate("LazyVim.telescope", "LazyVim.pick")
return LazyVim.pick.wrap(...)
end
function M.config_files()
return LazyVim.pick.config_files()
end
return M