208 lines
8.5 KiB
Lua
208 lines
8.5 KiB
Lua
local ui = require("util.icons").ui
|
|
|
|
local builtin = function(name, opts)
|
|
return function(title)
|
|
return function()
|
|
local picker = require("telescope.builtin")[name]
|
|
picker(vim.tbl_extend("force", opts or {}, {
|
|
prompt_title = title,
|
|
}))
|
|
end
|
|
end
|
|
end
|
|
|
|
local pickers = setmetatable({
|
|
all_files = builtin("find_files", {
|
|
hidden = true,
|
|
no_ignore = true,
|
|
no_ignore_parent = true,
|
|
}),
|
|
all_man_pages = builtin("man_pages", {
|
|
sections = { "ALL" },
|
|
}),
|
|
colorscheme = builtin("colorscheme", { enable_preview = true }),
|
|
diagnostics = builtin("diagnostics", { bufnr = 0 }),
|
|
dotfiles = builtin("find_files", { cwd = "~/.dotfiles", hidden = true }),
|
|
plugins = builtin("find_files", {
|
|
cwd = vim.fn.stdpath("data") .. "/lazy",
|
|
}),
|
|
selection = function(title)
|
|
return function()
|
|
local text = require("util").get_selected_text()
|
|
return require("telescope.builtin").grep_string {
|
|
prompt_title = string.format(title .. ": %s ", text),
|
|
search = text,
|
|
}
|
|
end
|
|
end,
|
|
here = builtin("current_buffer_fuzzy_find"),
|
|
}, {
|
|
-- Fall back to telescope's built-in pickers if a custom one is not defined
|
|
-- above, but make sure to keep the title we defined.
|
|
__index = function(_, key) return builtin(key) end,
|
|
})
|
|
|
|
---@class LazyKeysSpec
|
|
---@field desc string
|
|
|
|
---Create consistent key maps with the same prefix and description style.
|
|
---@param spec LazyKeysSpec lazy.nvim key spec to modify
|
|
---@return LazyKeysSpec modified key spec with prefix and description
|
|
local keymap = function(spec)
|
|
vim.validate("Telescope key spec", spec, "table")
|
|
vim.validate("Telescope key lhs", spec[1], "string")
|
|
vim.validate("Telescope key rhs", spec[2], { "string", "function" })
|
|
vim.validate("Telescope key description", spec.desc, "string")
|
|
return vim.tbl_extend("force", spec, {
|
|
"<leader>f" .. spec[1], -- lhs
|
|
spec[2], -- rhs
|
|
desc = ui.Telescope .. " Telescope " .. spec.desc,
|
|
})
|
|
end
|
|
|
|
local keys = {
|
|
-- stylua: ignore start
|
|
{ "a", pickers.autocommands " Autocommands" , desc = "[a]utocommands" },
|
|
{ "b", pickers.buffers " Buffers" , desc = "[b]uffers" },
|
|
--"B" used in telescope-file-browser
|
|
{ "c", pickers.colorscheme " Colorschemes" , desc = "[c]olorschemes" },
|
|
{ "C", pickers.commands " Commands" , desc = "[C]ommands" },
|
|
{ "d", pickers.diagnostics " Diagnostics" , desc = "[d]iagnostics" },
|
|
--"e"
|
|
{ "f", pickers.find_files " Files" , desc = "[f]ind files" },
|
|
{ "F", pickers.all_files " ALL files" , desc = "all [F]iles" },
|
|
{ "gr", pickers.live_grep " Live grep" , desc = "Live [gr]ep" },
|
|
{ "gf", pickers.git_files " Git files" , desc = "[g]it [f]iles" },
|
|
{ "gc", pickers.git_commits " Commits" , desc = "[g]it [c]ommits" },
|
|
{ "h", pickers.here " Current buffer" , desc = "[b]uffer [h]ere" },
|
|
{ "H", pickers.highlights " Highlights" , desc = "[H]ighlights" },
|
|
--"i" used in nerdy
|
|
{ "j", pickers.jumplist " Jumplist" , desc = "[j]umplist" },
|
|
{ "k", pickers.keymaps " Keymaps" , desc = "[k]eymaps" },
|
|
{ "K", pickers.help_tags " Help tags" , desc = "[K] help/documentation" },
|
|
{ "l", pickers.loclist " Location list" , desc = "[l]ocation List" },
|
|
{ "m", pickers.all_man_pages " Man pages" , desc = "[m]an pages" },
|
|
--"n" used in vim-notify
|
|
{ "o", pickers.vim_options " Vim options" , desc = "[o]ptions" },
|
|
{ "p", pickers.plugins "", desc = "[p]lugins"},
|
|
{ "q", pickers.quickfix " Quickfix" , desc = "[q]uickfix" },
|
|
{ "r", pickers.lsp_references " References" , desc = "[r]eferences" },
|
|
{ "R", pickers.registers " Registers" , desc = "[R]registers" },
|
|
{ "s", pickers.lsp_document_symbols " Document Symbols " , desc = "LSP document [s]ymbols" },
|
|
{ "S", pickers.lsp_workspace_symbols " Workspace Symbols " , desc = "LSP workspace [S]ymbols" },
|
|
--"t" used in todo_comments
|
|
{ "T", pickers.treesitter " Treesitter symbols" , desc = "[T]reesitter Symbols" },
|
|
--"u"
|
|
--"v"
|
|
{ "w", pickers.selection " Grep" , desc = "[w]word under cursor" },
|
|
{ "w", pickers.selection " Grep", mode = "v" , desc = "[w]ord(s) selected" },
|
|
--"x"
|
|
--"y"
|
|
{ "z", pickers.spell_suggest " Spelling suggestions" , desc = "[z] spell suggestions" },
|
|
{ ".", pickers.dotfiles " Dotfiles" , desc = "[.]dotfiles" },
|
|
{ ":", pickers.command_history " Command history" , desc = "[:]command history" },
|
|
{ "/", pickers.search_history " Search history" , desc = "[/]search history" },
|
|
{ " ", pickers.resume " Resume" , desc = "Resume " },
|
|
-- stylua: ignore end
|
|
}
|
|
|
|
return {
|
|
"nvim-telescope/telescope.nvim",
|
|
|
|
dependencies = {
|
|
"nvim-telescope/telescope-fzf-native.nvim",
|
|
build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release "
|
|
.. "&& cmake --build build --config Release "
|
|
.. "&& cmake --install build --prefix build",
|
|
},
|
|
|
|
cmd = "Telescope",
|
|
|
|
---@diagnostic disable-next-line: param-type-mismatch
|
|
keys = vim.iter(keys):map(keymap):totable(),
|
|
|
|
-- Export this function so we can use in other plugins.
|
|
keymap = keymap,
|
|
|
|
opts = function()
|
|
local actions = require("telescope.actions")
|
|
local layout = require("telescope.actions.layout")
|
|
local state = require("telescope.actions.state")
|
|
|
|
local clear_prompt = function(prompt_bufnr)
|
|
state.get_current_picker(prompt_bufnr):reset_prompt()
|
|
end
|
|
|
|
local mappings = {
|
|
["<c-y>"] = layout.cycle_layout_next,
|
|
["<c-u>"] = clear_prompt,
|
|
["<c-i>"] = actions.toggle_selection + actions.move_selection_next,
|
|
["<c-o>"] = actions.toggle_selection + actions.move_selection_previous,
|
|
["<c-p>"] = layout.toggle_preview,
|
|
|
|
["<c-j>"] = actions.move_selection_next,
|
|
["<c-k>"] = actions.move_selection_previous,
|
|
|
|
["<c-f>"] = actions.results_scrolling_down,
|
|
["<c-b>"] = actions.results_scrolling_up,
|
|
|
|
["<s-down>"] = actions.preview_scrolling_down,
|
|
["<s-up>"] = actions.preview_scrolling_up,
|
|
|
|
["<c-s>"] = actions.select_horizontal,
|
|
["<c-x>"] = false,
|
|
["<c-c>"] = actions.close,
|
|
|
|
["<c-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
|
|
["<c-l>"] = actions.smart_send_to_loclist + actions.open_loclist,
|
|
}
|
|
|
|
return {
|
|
defaults = {
|
|
mappings = { i = mappings, n = mappings },
|
|
|
|
prompt_prefix = " " .. ui.Telescope .. " ",
|
|
selection_caret = ui.Play .. " ",
|
|
|
|
multi_icon = ui.Checkbox .. " ",
|
|
scroll_strategy = "limit", -- Don't wrap around in results.
|
|
|
|
dynamic_preview_title = true,
|
|
|
|
layout_strategy = "flex",
|
|
layout_config = {
|
|
width = 0.9,
|
|
height = 0.9,
|
|
flex = { flip_columns = 180 },
|
|
horizontal = { preview_width = 0.5 },
|
|
vertical = { preview_height = 0.5 },
|
|
},
|
|
cycle_layout_list = {
|
|
"horizontal",
|
|
"vertical",
|
|
},
|
|
},
|
|
pickers = {
|
|
buffers = {
|
|
mappings = {
|
|
n = { x = actions.delete_buffer },
|
|
i = { ["<c-x>"] = actions.delete_buffer },
|
|
},
|
|
},
|
|
colorscheme = { theme = "dropdown" },
|
|
spell_suggest = { theme = "cursor" },
|
|
},
|
|
}
|
|
end,
|
|
|
|
config = function(_, opts)
|
|
require("telescope").setup(opts)
|
|
require("telescope").load_extension("fzf")
|
|
vim.api.nvim_create_autocmd("User", {
|
|
desc = "Enable line number in Telescope previewers.",
|
|
group = vim.api.nvim_create_augroup("custom.telescope", { clear = true }),
|
|
pattern = "TelescopePreviewerLoaded",
|
|
command = "setlocal number",
|
|
})
|
|
end,
|
|
}
|