You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

228 lines
8.3 KiB

return {
"nvim-telescope/telescope.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"debugloop/telescope-undo.nvim",
"nvim-telescope/telescope-ui-select.nvim",
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
},
config = function()
local telescope = require("telescope")
local actions = require("telescope.actions")
local builtin = require("telescope.builtin")
local previewers = require("telescope.previewers")
local previewers_utils = require("telescope.previewers.utils")
-- Configuration constants
local MAX_FILE_SIZE = 100000
-- Enable line numbers in telescope previews
vim.api.nvim_create_autocmd('User', {
pattern = 'TelescopePreviewerLoaded',
callback = function()
vim.wo.number = true
end,
})
-- Truncate large files in preview to improve performance
local function truncate_large_files(filepath, bufnr, opts)
opts = opts or {}
filepath = vim.fn.expand(filepath)
vim.uv.fs_stat(filepath, function(_, stat)
if not stat then return end
if stat.size > MAX_FILE_SIZE then
local cmd = { "head", "-c", tostring(MAX_FILE_SIZE), filepath }
previewers_utils.job_maker(cmd, bufnr, opts)
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)
end
-- Cache git status to avoid repeated system calls
local is_inside_work_tree = {}
local function smart_project_files()
local cwd = vim.fn.getcwd()
if is_inside_work_tree[cwd] == nil then
vim.fn.system("git rev-parse --is-inside-work-tree")
is_inside_work_tree[cwd] = vim.v.shell_error == 0
end
local opts = is_inside_work_tree[cwd]
and { show_untracked = true, hidden = true }
or {}
local picker = is_inside_work_tree[cwd]
and builtin.git_files
or builtin.find_files
picker(opts)
end
-- Telescope setup
telescope.setup({
defaults = {
file_sorter = require("telescope.sorters").get_fzy_sorter,
color_devicons = true,
buffer_previewer_maker = truncate_large_files,
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "ascending",
path_display = { "truncate" },
layout_config = {
prompt_position = "top",
horizontal = {
preview_width = 0.6,
},
vertical = {
mirror = false,
},
},
-- Modern borderchars
borderchars = { "", "", "", "", "", "", "", "" },
-- Performance optimizations
use_less = true,
set_env = { COLORTERM = "truecolor" },
mappings = {
i = {
["<C-n>"] = actions.move_selection_next,
["<C-p>"] = actions.move_selection_previous,
["<C-j>"] = actions.cycle_history_next,
["<C-k>"] = actions.cycle_history_prev,
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
["<C-u>"] = false, -- Clear prompt
["<C-c>"] = actions.close, -- Close prompt
},
n = {
["q"] = actions.close,
},
},
},
pickers = {
diagnostics = {
initial_mode = "normal",
layout_config = {
preview_cutoff = 9999,
},
},
buffers = {
sort_mru = true,
sort_lastused = true,
mappings = {
i = {
["<C-d>"] = actions.delete_buffer,
},
n = {
["dd"] = actions.delete_buffer,
},
},
},
find_files = {
hidden = true,
find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" },
},
},
extensions = {
undo = {
side_by_side = true,
layout_strategy = "vertical",
layout_config = {
preview_height = 0.8,
},
mappings = {
i = {
["<CR>"] = require("telescope-undo.actions").restore,
},
n = {
["<CR>"] = require("telescope-undo.actions").restore,
["y"] = require("telescope-undo.actions").yank_additions,
["Y"] = require("telescope-undo.actions").yank_deletions,
["u"] = require("telescope-undo.actions").restore,
},
},
},
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true,
case_mode = "smart_case",
},
},
})
-- Load extensions
telescope.load_extension("fzf")
telescope.load_extension("undo")
telescope.load_extension("ui-select")
-- Keymaps
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { desc = desc, noremap = true, silent = true })
end
-- File navigation
map("n", "<leader>ff", function()
require("plugins.telescope.multigrep").live_multgrep()
end, "Live multigrep")
map("n", "<leader>p", smart_project_files, "Find project files")
map("n", "<leader>fr", builtin.resume, "Resume last telescope")
map("n", "<leader>fb", builtin.buffers, "Find buffers")
map("n", "<leader>fo", builtin.oldfiles, "Find recent files")
-- Search
map("n", "<leader>gf", function()
builtin.grep_string({ search = vim.fn.expand("<cword>") })
end, "Grep word under cursor")
map("n", "<leader>gF", function()
builtin.grep_string({ search = vim.fn.expand("<cWORD>") })
end, "Grep WORD under cursor")
map("n", "<leader>gD", function()
builtin.find_files({ search_file = vim.fn.expand("<cword>") })
end, "Find file with name under cursor")
-- Git
map("n", "<leader>gb", function()
builtin.git_branches({
attach_mappings = function(_, map_func)
map_func("i", "<C-d>", actions.git_delete_branch)
map_func("n", "<C-d>", actions.git_delete_branch)
return true
end,
})
end, "Git branches")
map("n", "<leader>gc", builtin.git_commits, "Git commits")
-- LSP
map("n", "<leader>ds", builtin.lsp_document_symbols, "Document symbols")
map("n", "<leader>ws", builtin.lsp_workspace_symbols, "Workspace symbols")
map("n", "<leader>dws", builtin.lsp_dynamic_workspace_symbols, "Dynamic workspace symbols")
-- Utilities
map("n", "<leader>u", "<cmd>Telescope undo<cr>", "Undo history")
map("n", "<leader>ss", builtin.spell_suggest, "Spell suggestions")
map("n", "<leader>m", builtin.marks, "Marks")
map("n", "<leader>cc", builtin.commands, "Commands")
map("n", "<leader>ch", builtin.command_history, "Command history")
map("n", "<leader>vh", builtin.help_tags, "Help tags")
-- Quickfix
map("n", "<leader>ql", builtin.quickfix, "Quickfix list")
map("n", "<leader>qhl", builtin.quickfixhistory, "Quickfix history")
end,
}