mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-28 05:54:03 +02:00
feat: better telescope integration (#1702)
This commit is contained in:
parent
f87416c141
commit
ef41a3d24e
4 changed files with 149 additions and 123 deletions
|
@ -8,11 +8,6 @@ function M.config()
|
||||||
on_config_done = nil,
|
on_config_done = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
local status_ok, actions = pcall(require, "telescope.actions")
|
|
||||||
if not status_ok then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
|
lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
|
||||||
defaults = {
|
defaults = {
|
||||||
prompt_prefix = " ",
|
prompt_prefix = " ",
|
||||||
|
@ -28,135 +23,44 @@ function M.config()
|
||||||
horizontal = { mirror = false },
|
horizontal = { mirror = false },
|
||||||
vertical = { mirror = false },
|
vertical = { mirror = false },
|
||||||
},
|
},
|
||||||
file_sorter = require("telescope.sorters").get_fzy_sorter,
|
vimgrep_arguments = {
|
||||||
|
"rg",
|
||||||
|
"--color=never",
|
||||||
|
"--no-heading",
|
||||||
|
"--with-filename",
|
||||||
|
"--line-number",
|
||||||
|
"--column",
|
||||||
|
"--smart-case",
|
||||||
|
"--hidden",
|
||||||
|
},
|
||||||
file_ignore_patterns = {},
|
file_ignore_patterns = {},
|
||||||
generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter,
|
|
||||||
path_display = { shorten = 5 },
|
path_display = { shorten = 5 },
|
||||||
winblend = 0,
|
winblend = 0,
|
||||||
border = {},
|
border = {},
|
||||||
borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
|
borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
|
||||||
color_devicons = true,
|
color_devicons = true,
|
||||||
use_less = true,
|
|
||||||
set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
|
set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
|
||||||
file_previewer = require("telescope.previewers").vim_buffer_cat.new,
|
pickers = {
|
||||||
grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new,
|
find_files = {
|
||||||
qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new,
|
find_command = { "fd", "--type=file", "--hidden", "--smart-case" },
|
||||||
|
|
||||||
-- Developer configurations: Not meant for general override
|
|
||||||
-- buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker,
|
|
||||||
mappings = {
|
|
||||||
i = {
|
|
||||||
["<C-n>"] = actions.move_selection_next,
|
|
||||||
["<C-p>"] = actions.move_selection_previous,
|
|
||||||
["<C-c>"] = actions.close,
|
|
||||||
["<C-j>"] = actions.cycle_history_next,
|
|
||||||
["<C-k>"] = actions.cycle_history_prev,
|
|
||||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
|
||||||
["<CR>"] = actions.select_default + actions.center,
|
|
||||||
-- To disable a keymap, put [map] = false
|
|
||||||
-- So, to not map "<C-n>", just put
|
|
||||||
-- ["<c-t>"] = trouble.open_with_trouble,
|
|
||||||
-- ["<c-x>"] = false,
|
|
||||||
-- ["<esc>"] = actions.close,
|
|
||||||
-- Otherwise, just set the mapping to the function that you want it to be.
|
|
||||||
-- ["<C-i>"] = actions.select_horizontal,
|
|
||||||
-- Add up multiple actions
|
|
||||||
-- You can perform as many actions in a row as you like
|
|
||||||
-- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
|
|
||||||
},
|
},
|
||||||
n = {
|
live_grep = {
|
||||||
["<C-n>"] = actions.move_selection_next,
|
--@usage don't include the filename in the search results
|
||||||
["<C-p>"] = actions.move_selection_previous,
|
only_sort_text = true,
|
||||||
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
|
||||||
-- ["<c-t>"] = trouble.open_with_trouble,
|
|
||||||
-- ["<C-i>"] = my_cool_custom_action,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extensions = {
|
extensions = {
|
||||||
fzy_native = {
|
fzf = {
|
||||||
override_generic_sorter = false,
|
fuzzy = true, -- false will only do exact matching
|
||||||
override_file_sorter = true,
|
override_generic_sorter = true, -- override the generic sorter
|
||||||
|
override_file_sorter = true, -- override the file sorter
|
||||||
|
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.find_lunarvim_files(opts)
|
|
||||||
opts = opts or {}
|
|
||||||
local themes = require "telescope.themes"
|
|
||||||
local theme_opts = themes.get_ivy {
|
|
||||||
sorting_strategy = "ascending",
|
|
||||||
layout_strategy = "bottom_pane",
|
|
||||||
prompt_prefix = ">> ",
|
|
||||||
prompt_title = "~ LunarVim files ~",
|
|
||||||
cwd = get_runtime_dir(),
|
|
||||||
search_dirs = { get_runtime_dir() .. "/lvim", lvim.lsp.templates_dir },
|
|
||||||
}
|
|
||||||
opts = vim.tbl_deep_extend("force", theme_opts, opts)
|
|
||||||
require("telescope.builtin").find_files(opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.grep_lunarvim_files(opts)
|
|
||||||
opts = opts or {}
|
|
||||||
local themes = require "telescope.themes"
|
|
||||||
local theme_opts = themes.get_ivy {
|
|
||||||
sorting_strategy = "ascending",
|
|
||||||
layout_strategy = "bottom_pane",
|
|
||||||
prompt_prefix = ">> ",
|
|
||||||
prompt_title = "~ search LunarVim ~",
|
|
||||||
cwd = get_runtime_dir(),
|
|
||||||
search_dirs = { get_runtime_dir() .. "/lvim", lvim.lsp.templates_dir },
|
|
||||||
}
|
|
||||||
opts = vim.tbl_deep_extend("force", theme_opts, opts)
|
|
||||||
require("telescope.builtin").live_grep(opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.view_lunarvim_changelog()
|
|
||||||
local finders = require "telescope.finders"
|
|
||||||
local make_entry = require "telescope.make_entry"
|
|
||||||
local pickers = require "telescope.pickers"
|
|
||||||
local previewers = require "telescope.previewers"
|
|
||||||
local actions = require "telescope.actions"
|
|
||||||
local opts = {}
|
|
||||||
|
|
||||||
local conf = require("telescope.config").values
|
|
||||||
opts.entry_maker = make_entry.gen_from_git_commits(opts)
|
|
||||||
|
|
||||||
pickers.new(opts, {
|
|
||||||
prompt_title = "LunarVim changelog",
|
|
||||||
|
|
||||||
finder = finders.new_oneshot_job(
|
|
||||||
vim.tbl_flatten {
|
|
||||||
"git",
|
|
||||||
"log",
|
|
||||||
"--pretty=oneline",
|
|
||||||
"--abbrev-commit",
|
|
||||||
"--",
|
|
||||||
".",
|
|
||||||
},
|
|
||||||
opts
|
|
||||||
),
|
|
||||||
previewer = {
|
|
||||||
previewers.git_commit_diff_to_parent.new(opts),
|
|
||||||
previewers.git_commit_diff_to_head.new(opts),
|
|
||||||
previewers.git_commit_diff_as_was.new(opts),
|
|
||||||
previewers.git_commit_message.new(opts),
|
|
||||||
},
|
|
||||||
|
|
||||||
--TODO: consider opening a diff view when pressing enter
|
|
||||||
attach_mappings = function(_, map)
|
|
||||||
map("i", "<enter>", actions._close)
|
|
||||||
map("n", "<enter>", actions._close)
|
|
||||||
map("i", "<esc>", actions._close)
|
|
||||||
map("n", "<esc>", actions._close)
|
|
||||||
map("n", "q", actions._close)
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
sorter = conf.file_sorter(opts),
|
|
||||||
}):find()
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.code_actions()
|
function M.code_actions()
|
||||||
local opts = {
|
local opts = {
|
||||||
winblend = 15,
|
winblend = 15,
|
||||||
|
@ -174,20 +78,57 @@ function M.code_actions()
|
||||||
previewer = false,
|
previewer = false,
|
||||||
shorten_path = false,
|
shorten_path = false,
|
||||||
}
|
}
|
||||||
require("telescope.builtin").lsp_code_actions(require("telescope.themes").get_dropdown(opts))
|
local builtin = require "telescope.builtin"
|
||||||
|
local themes = require "telescope.themes"
|
||||||
|
builtin.lsp_code_actions(themes.get_dropdown(opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
local telescope = require "telescope"
|
local previewers = require "telescope.previewers"
|
||||||
|
local sorters = require "telescope.sorters"
|
||||||
|
local actions = require "telescope.actions"
|
||||||
|
|
||||||
|
lvim.builtin.telescope = vim.tbl_extend("keep", {
|
||||||
|
file_previewer = previewers.vim_buffer_cat.new,
|
||||||
|
grep_previewer = previewers.vim_buffer_vimgrep.new,
|
||||||
|
qflist_previewer = previewers.vim_buffer_qflist.new,
|
||||||
|
file_sorter = sorters.get_fuzzy_file,
|
||||||
|
generic_sorter = sorters.get_generic_fuzzy_sorter,
|
||||||
|
---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults.
|
||||||
|
mappings = {
|
||||||
|
i = {
|
||||||
|
["<C-n>"] = actions.move_selection_next,
|
||||||
|
["<C-p>"] = actions.move_selection_previous,
|
||||||
|
["<C-c>"] = actions.close,
|
||||||
|
["<C-j>"] = actions.cycle_history_next,
|
||||||
|
["<C-k>"] = actions.cycle_history_prev,
|
||||||
|
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||||
|
["<CR>"] = actions.select_default + actions.center,
|
||||||
|
},
|
||||||
|
n = {
|
||||||
|
["<C-n>"] = actions.move_selection_next,
|
||||||
|
["<C-p>"] = actions.move_selection_previous,
|
||||||
|
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, lvim.builtin.telescope)
|
||||||
|
|
||||||
|
local telescope = require "telescope"
|
||||||
telescope.setup(lvim.builtin.telescope)
|
telescope.setup(lvim.builtin.telescope)
|
||||||
|
|
||||||
if lvim.builtin.project.active then
|
if lvim.builtin.project.active then
|
||||||
telescope.load_extension "projects"
|
pcall(function()
|
||||||
|
require("telescope").load_extension "projects"
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
if lvim.builtin.telescope.on_config_done then
|
if lvim.builtin.telescope.on_config_done then
|
||||||
lvim.builtin.telescope.on_config_done(telescope)
|
lvim.builtin.telescope.on_config_done(telescope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if lvim.builtin.telescope.extensions and lvim.builtin.telescope.extensions.fzf then
|
||||||
|
require("telescope").load_extension "fzf"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
80
lua/lvim/core/telescope/custom-finders.lua
Normal file
80
lua/lvim/core/telescope/custom-finders.lua
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local _, builtin = pcall(require, "telescope.builtin")
|
||||||
|
local _, finders = pcall(require, "telescope.finders")
|
||||||
|
local _, pickers = pcall(require, "telescope.pickers")
|
||||||
|
local _, sorters = pcall(require, "telescope.sorters")
|
||||||
|
local _, themes = pcall(require, "telescope.themes")
|
||||||
|
local _, actions = pcall(require, "telescope.actions")
|
||||||
|
local _, previewers = pcall(require, "telescope.previewers")
|
||||||
|
local _, make_entry = pcall(require, "telescope.make_entry")
|
||||||
|
|
||||||
|
local utils = require "lvim.utils"
|
||||||
|
|
||||||
|
function M.find_lunarvim_files(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
local theme_opts = themes.get_ivy {
|
||||||
|
sorting_strategy = "ascending",
|
||||||
|
layout_strategy = "bottom_pane",
|
||||||
|
prompt_prefix = ">> ",
|
||||||
|
prompt_title = "~ LunarVim files ~",
|
||||||
|
cwd = get_runtime_dir(),
|
||||||
|
search_dirs = { utils.join_paths(get_runtime_dir(), "lvim"), lvim.lsp.templates_dir },
|
||||||
|
}
|
||||||
|
opts = vim.tbl_deep_extend("force", theme_opts, opts)
|
||||||
|
builtin.find_files(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.grep_lunarvim_files(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
local theme_opts = themes.get_ivy {
|
||||||
|
sorting_strategy = "ascending",
|
||||||
|
layout_strategy = "bottom_pane",
|
||||||
|
prompt_prefix = ">> ",
|
||||||
|
prompt_title = "~ search LunarVim ~",
|
||||||
|
cwd = get_runtime_dir(),
|
||||||
|
search_dirs = { utils.join_paths(get_runtime_dir(), "lvim"), lvim.lsp.templates_dir },
|
||||||
|
}
|
||||||
|
opts = vim.tbl_deep_extend("force", theme_opts, opts)
|
||||||
|
builtin.live_grep(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.view_lunarvim_changelog()
|
||||||
|
local opts = {}
|
||||||
|
opts.entry_maker = make_entry.gen_from_git_commits(opts)
|
||||||
|
|
||||||
|
pickers.new(opts, {
|
||||||
|
prompt_title = "LunarVim changelog",
|
||||||
|
|
||||||
|
finder = finders.new_oneshot_job(
|
||||||
|
vim.tbl_flatten {
|
||||||
|
"git",
|
||||||
|
"log",
|
||||||
|
"--pretty=oneline",
|
||||||
|
"--abbrev-commit",
|
||||||
|
"--",
|
||||||
|
".",
|
||||||
|
},
|
||||||
|
opts
|
||||||
|
),
|
||||||
|
previewer = {
|
||||||
|
previewers.git_commit_diff_to_parent.new(opts),
|
||||||
|
previewers.git_commit_diff_to_head.new(opts),
|
||||||
|
previewers.git_commit_diff_as_was.new(opts),
|
||||||
|
previewers.git_commit_message.new(opts),
|
||||||
|
},
|
||||||
|
|
||||||
|
--TODO: consider opening a diff view when pressing enter
|
||||||
|
attach_mappings = function(_, map)
|
||||||
|
map("i", "<enter>", actions._close)
|
||||||
|
map("n", "<enter>", actions._close)
|
||||||
|
map("i", "<esc>", actions._close)
|
||||||
|
map("n", "<esc>", actions._close)
|
||||||
|
map("n", "q", actions._close)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
sorter = sorters.generic_sorter,
|
||||||
|
}):find()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -181,11 +181,11 @@ M.config = function()
|
||||||
"Edit config.lua",
|
"Edit config.lua",
|
||||||
},
|
},
|
||||||
f = {
|
f = {
|
||||||
"<cmd>lua require('lvim.core.telescope').find_lunarvim_files()<cr>",
|
"<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>",
|
||||||
"Find LunarVim files",
|
"Find LunarVim files",
|
||||||
},
|
},
|
||||||
g = {
|
g = {
|
||||||
"<cmd>lua require('lvim.core.telescope').grep_lunarvim_files()<cr>",
|
"<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>",
|
||||||
"Grep LunarVim files",
|
"Grep LunarVim files",
|
||||||
},
|
},
|
||||||
k = { "<cmd>lua require('lvim.keymappings').print()<cr>", "View LunarVim's default keymappings" },
|
k = { "<cmd>lua require('lvim.keymappings').print()<cr>", "View LunarVim's default keymappings" },
|
||||||
|
@ -194,7 +194,7 @@ M.config = function()
|
||||||
"Toggle LunarVim Info",
|
"Toggle LunarVim Info",
|
||||||
},
|
},
|
||||||
I = {
|
I = {
|
||||||
"<cmd>lua require('lvim.core.telescope').view_lunarvim_changelog()<cr>",
|
"<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>",
|
||||||
"View LunarVim's changelog",
|
"View LunarVim's changelog",
|
||||||
},
|
},
|
||||||
l = {
|
l = {
|
||||||
|
|
|
@ -19,6 +19,11 @@ return {
|
||||||
end,
|
end,
|
||||||
disable = not lvim.builtin.telescope.active,
|
disable = not lvim.builtin.telescope.active,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"nvim-telescope/telescope-fzf-native.nvim",
|
||||||
|
run = "make",
|
||||||
|
disable = not lvim.builtin.telescope.active,
|
||||||
|
},
|
||||||
-- Install nvim-cmp, and buffer source as a dependency
|
-- Install nvim-cmp, and buffer source as a dependency
|
||||||
{
|
{
|
||||||
"hrsh7th/nvim-cmp",
|
"hrsh7th/nvim-cmp",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue