mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-08-02 09:05:00 +02:00
feat(extras): added fzf-lua (#3555)
New extra with an initial implementation of fzf-lua. ## Todo - [x] check all places that currently depend on telescope and provide an alternative or disable - [x] disable telescope spec completely. (currently only removed its keymaps) - [x] trouble integration - [x] https://github.com/ibhagwan/fzf-lua/issues/1241 --------- Co-authored-by: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com>
This commit is contained in:
parent
caaa6c440d
commit
6ab404134d
7 changed files with 320 additions and 65 deletions
|
@ -17,6 +17,7 @@ local LazyUtil = require("lazy.core.util")
|
|||
---@field json lazyvim.util.json
|
||||
---@field lualine lazyvim.util.lualine
|
||||
---@field mini lazyvim.util.mini
|
||||
---@field pick lazyvim.util.pick
|
||||
---@field cmp lazyvim.util.cmp
|
||||
local M = {}
|
||||
|
||||
|
@ -281,4 +282,5 @@ function M.memoize(fn)
|
|||
return cache[key]
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
72
lua/lazyvim/util/pick.lua
Normal file
72
lua/lazyvim/util/pick.lua
Normal file
|
@ -0,0 +1,72 @@
|
|||
---@class lazyvim.util.pick
|
||||
---@overload fun(command:string, opts?:lazyvim.util.pick.Opts): fun()
|
||||
local M = setmetatable({}, {
|
||||
__call = function(m, ...)
|
||||
return m.wrap(...)
|
||||
end,
|
||||
})
|
||||
|
||||
---@class lazyvim.util.pick.Opts: table<string, any>
|
||||
---@field root? boolean
|
||||
---@field cwd? string
|
||||
---@field buf? number
|
||||
---@field show_untracked? boolean
|
||||
|
||||
---@type table<string, string>
|
||||
M.commands = {
|
||||
files = "find_files",
|
||||
}
|
||||
|
||||
---@param command? string
|
||||
---@param opts? lazyvim.util.pick.Opts
|
||||
function M.open(command, opts)
|
||||
command = command or "auto"
|
||||
opts = opts or {}
|
||||
|
||||
opts = vim.deepcopy(opts)
|
||||
|
||||
if type(opts.cwd) == "boolean" then
|
||||
LazyVim.warn("LazyVim.pick: opts.cwd should be a string or nil")
|
||||
opts.cwd = nil
|
||||
end
|
||||
|
||||
if not opts.cwd and opts.root ~= false then
|
||||
opts.cwd = LazyVim.root({ buf = opts.buf })
|
||||
end
|
||||
|
||||
local cwd = opts.cwd or vim.uv.cwd()
|
||||
if command == "auto" then
|
||||
command = "files"
|
||||
if
|
||||
vim.uv.fs_stat(cwd .. "/.git")
|
||||
and not vim.uv.fs_stat(cwd .. "/.ignore")
|
||||
and not vim.uv.fs_stat(cwd .. "/.rgignore")
|
||||
then
|
||||
command = "git_files"
|
||||
opts.show_untracked = opts.show_untracked ~= false
|
||||
end
|
||||
end
|
||||
command = M.commands[command] or command
|
||||
M._open(command, opts)
|
||||
end
|
||||
|
||||
---@param command? string
|
||||
---@param opts? lazyvim.util.pick.Opts
|
||||
function M.wrap(command, opts)
|
||||
opts = opts or {}
|
||||
return function()
|
||||
M.open(command, vim.deepcopy(opts))
|
||||
end
|
||||
end
|
||||
|
||||
---@param command string
|
||||
---@param opts? lazyvim.util.pick.Opts
|
||||
function M._open(command, opts)
|
||||
return LazyVim.telescope.open(command, opts)
|
||||
end
|
||||
|
||||
function M.config_files()
|
||||
return M.wrap("files", { cwd = vim.fn.stdpath("config") })
|
||||
end
|
||||
|
||||
return M
|
|
@ -168,13 +168,14 @@ end
|
|||
-- * lsp root_dir
|
||||
-- * root pattern of filename of the current buffer
|
||||
-- * root pattern of cwd
|
||||
---@param opts? {normalize?:boolean}
|
||||
---@param opts? {normalize?:boolean, buf?:number}
|
||||
---@return string
|
||||
function M.get(opts)
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
opts = opts or {}
|
||||
local buf = opts.buf or vim.api.nvim_get_current_buf()
|
||||
local ret = M.cache[buf]
|
||||
if not ret then
|
||||
local roots = M.detect({ all = false })
|
||||
local roots = M.detect({ all = false, buf = buf })
|
||||
ret = roots[1] and roots[1].paths[1] or vim.uv.cwd()
|
||||
M.cache[buf] = ret
|
||||
end
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
---@class lazyvim.util.telescope.opts
|
||||
---@field cwd? string|boolean
|
||||
---@field show_untracked? boolean
|
||||
|
||||
---@class lazyvim.util.telescope
|
||||
---@overload fun(builtin:string, opts?:lazyvim.util.telescope.opts)
|
||||
---@overload fun(builtin:string, opts?:lazyvim.util.pick.Opts)
|
||||
local M = setmetatable({}, {
|
||||
__call = function(m, ...)
|
||||
return m.telescope(...)
|
||||
|
@ -14,50 +10,39 @@ local M = setmetatable({}, {
|
|||
-- 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.telescope.opts
|
||||
function M.telescope(builtin, opts)
|
||||
local params = { builtin = builtin, opts = opts }
|
||||
return function()
|
||||
builtin = params.builtin
|
||||
opts = params.opts
|
||||
opts = vim.tbl_deep_extend("force", { cwd = LazyVim.root() }, opts or {}) --[[@as lazyvim.util.telescope.opts]]
|
||||
if builtin == "files" then
|
||||
if
|
||||
vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.git")
|
||||
and not vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.ignore")
|
||||
and not vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.rgignore")
|
||||
then
|
||||
if opts.show_untracked == nil then
|
||||
opts.show_untracked = true
|
||||
end
|
||||
builtin = "git_files"
|
||||
else
|
||||
builtin = "find_files"
|
||||
end
|
||||
---@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
|
||||
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()
|
||||
M.telescope(
|
||||
params.builtin,
|
||||
vim.tbl_deep_extend("force", {}, params.opts or {}, { cwd = 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
|
||||
---@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
|
||||
|
||||
require("telescope.builtin")[builtin](opts)
|
||||
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.telescope("find_files", { cwd = vim.fn.stdpath("config") })
|
||||
return LazyVim.pick.config_files()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue