|
|
@ -10,31 +10,31 @@ return { |
|
|
|
config = function() |
|
|
|
local telescope = require("telescope") |
|
|
|
local actions = require("telescope.actions") |
|
|
|
local action_state = require('telescope.actions.state') |
|
|
|
local builtin = require("telescope.builtin") |
|
|
|
local previewers = require("telescope.previewers") |
|
|
|
local previewers_utils = require("telescope.previewers.utils") |
|
|
|
local sorters = require("telescope.sorters") |
|
|
|
local builtin = require("telescope.builtin") |
|
|
|
|
|
|
|
-- Configuration constants |
|
|
|
local MAX_FILE_SIZE = 100000 |
|
|
|
|
|
|
|
-- Enable line numbers in telescope previews |
|
|
|
vim.api.nvim_create_autocmd('User', { |
|
|
|
pattern = 'TelescopePreviewerLoaded', |
|
|
|
callback = function(args) |
|
|
|
callback = function() |
|
|
|
vim.wo.number = true |
|
|
|
end, |
|
|
|
}) |
|
|
|
|
|
|
|
local max_size = 100000 |
|
|
|
local truncate_large_files = function(filepath, bufnr, opts) |
|
|
|
-- Truncate large files in preview to improve performance |
|
|
|
local function truncate_large_files(filepath, bufnr, opts) |
|
|
|
opts = opts or {} |
|
|
|
|
|
|
|
filepath = vim.fn.expand(filepath) |
|
|
|
---@diagnostic disable-next-line: undefined-field |
|
|
|
vim.loop.fs_stat(filepath, function(_, stat) |
|
|
|
if not stat then |
|
|
|
return |
|
|
|
end |
|
|
|
if stat.size > max_size then |
|
|
|
local cmd = { "head", "-c", max_size, 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) |
|
|
@ -42,9 +42,32 @@ return { |
|
|
|
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 = sorters.get_fzy_sorter, |
|
|
|
file_sorter = require("telescope.sorters").get_fzy_sorter, |
|
|
|
color_devicons = true, |
|
|
|
buffer_previewer_maker = truncate_large_files, |
|
|
|
|
|
|
@ -55,13 +78,20 @@ return { |
|
|
|
|
|
|
|
layout_config = { |
|
|
|
prompt_position = "top", |
|
|
|
horizontal = { |
|
|
|
preview_width = 0.6, |
|
|
|
}, |
|
|
|
vertical = { |
|
|
|
mirror = false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
border = {}, |
|
|
|
-- borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, |
|
|
|
borderchars = { " ", " ", " ", " ", " ", " ", " ", " " }, |
|
|
|
-- Modern borderchars |
|
|
|
borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, |
|
|
|
|
|
|
|
-- Performance optimizations |
|
|
|
use_less = true, |
|
|
|
set_env = { ['COLORTERM'] = 'truecolor' }, |
|
|
|
set_env = { COLORTERM = "truecolor" }, |
|
|
|
|
|
|
|
mappings = { |
|
|
|
i = { |
|
|
@ -70,9 +100,15 @@ return { |
|
|
|
["<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", |
|
|
@ -80,10 +116,31 @@ return { |
|
|
|
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, |
|
|
@ -96,91 +153,76 @@ return { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
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") |
|
|
|
|
|
|
|
-- We cache the results of "git rev-parse" |
|
|
|
-- Process creation is expensive in Windows, so this reduces latency |
|
|
|
local is_inside_work_tree = {} |
|
|
|
|
|
|
|
local project_files = function() |
|
|
|
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 |
|
|
|
|
|
|
|
if is_inside_work_tree[cwd] then |
|
|
|
builtin.git_files({ show_untracked = true, hidden = true }) |
|
|
|
else |
|
|
|
builtin.find_files({}) |
|
|
|
end |
|
|
|
-- Keymaps |
|
|
|
local function map(mode, lhs, rhs, desc) |
|
|
|
vim.keymap.set(mode, lhs, rhs, { desc = desc, noremap = true, silent = true }) |
|
|
|
end |
|
|
|
|
|
|
|
-- set keymaps |
|
|
|
local keymap = vim.keymap |
|
|
|
|
|
|
|
keymap.set("n", "<leader>ff", function() |
|
|
|
-- File navigation |
|
|
|
map("n", "<leader>ff", function() |
|
|
|
require("plugins.telescope.multigrep").live_multgrep() |
|
|
|
end, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>p", project_files, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>fr", builtin.resume, {}) |
|
|
|
end, "Live multigrep") |
|
|
|
|
|
|
|
keymap.set("n", "<leader>ss", builtin.spell_suggest, {}) |
|
|
|
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") |
|
|
|
|
|
|
|
keymap.set("n", "<leader>ql", builtin.quickfix, {}) |
|
|
|
keymap.set("n", "<leader>qhl", builtin.quickfixhistory, {}) |
|
|
|
-- Search |
|
|
|
map("n", "<leader>gf", function() |
|
|
|
builtin.grep_string({ search = vim.fn.expand("<cword>") }) |
|
|
|
end, "Grep word under cursor") |
|
|
|
|
|
|
|
keymap.set("n", "<leader>fb", builtin.buffers, {}) |
|
|
|
keymap.set("n", "<leader>fo", builtin.oldfiles, {}) |
|
|
|
map("n", "<leader>gF", function() |
|
|
|
builtin.grep_string({ search = vim.fn.expand("<cWORD>") }) |
|
|
|
end, "Grep WORD under cursor") |
|
|
|
|
|
|
|
keymap.set("n", "<leader>m", builtin.marks, {}) |
|
|
|
map("n", "<leader>gD", function() |
|
|
|
builtin.find_files({ search_file = vim.fn.expand("<cword>") }) |
|
|
|
end, "Find file with name under cursor") |
|
|
|
|
|
|
|
keymap.set("n", "<leader>cc", builtin.commands, {}) |
|
|
|
keymap.set("n", "<leader>ch", builtin.command_history, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>gb", function() |
|
|
|
-- Git |
|
|
|
map("n", "<leader>gb", function() |
|
|
|
builtin.git_branches({ |
|
|
|
attach_mappings = function(_, map) |
|
|
|
map("i", "<c-d>", actions.git_delete_branch) |
|
|
|
map("n", "<c-d>", actions.git_delete_branch) |
|
|
|
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, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>gc", builtin.git_commits, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>vh", builtin.help_tags, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>ds", builtin.lsp_document_symbols, {}) |
|
|
|
keymap.set("n", "<leader>ws", builtin.lsp_workspace_symbols, {}) |
|
|
|
keymap.set("n", "<leader>dws", builtin.lsp_dynamic_workspace_symbols, {}) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>gf", function() |
|
|
|
builtin.grep_string({ |
|
|
|
search = vim.fn.expand("<cword>"), |
|
|
|
}) |
|
|
|
end) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>gF", function() |
|
|
|
builtin.grep_string({ |
|
|
|
search = vim.fn.expand("<cWORD>"), |
|
|
|
}) |
|
|
|
end) |
|
|
|
|
|
|
|
keymap.set("n", "<leader>gD", function() |
|
|
|
builtin.find_files({ |
|
|
|
search_file = vim.fn.expand("<cword>"), |
|
|
|
}) |
|
|
|
end) |
|
|
|
|
|
|
|
vim.keymap.set("n", "<leader>u", "<cmd>Telescope undo<cr>") |
|
|
|
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, |
|
|
|
} |