X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/dc281eb2fbfb115fb9844dd9719722efdf4ae3d7..e13c0a2b5802f55a1aeab48dc9b88c18222cd5bd:/nvim/lua/plugins/picker.lua diff --git a/nvim/lua/plugins/picker.lua b/nvim/lua/plugins/picker.lua index 7b98619..347804f 100644 --- a/nvim/lua/plugins/picker.lua +++ b/nvim/lua/plugins/picker.lua @@ -1,312 +1,128 @@ -vim.g.lazyvim_picker = "telescope" - ----@type LazyPicker -local picker = { - name = "telescope", - commands = { - files = "find_files", - }, - -- this will return a function that calls telescope. - -- 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.pick.Opts - open = function(builtin, opts) - opts = opts or {} - opts.follow = opts.follow ~= false - 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 - ---@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", "", open_cwd_dir, { desc = "Open cwd Directory" }) - return true - end - end - - require("telescope.builtin")[builtin](opts) - end, -} - -if not LazyVim.pick.register(picker) then - return {} -end ---@type LazySpec return { - { "nvim-telescope/telescope.nvim", - cmd = "Telescope", - version = false, -- telescope did only one release, so use HEAD for now - 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", - config = function(plugin) - LazyVim.on_load("telescope.nvim", function() - local ok, err = pcall(require("telescope").load_extension, "fzf") - if not ok then - local lib = plugin.dir .. "/build/libfzf." .. (LazyVim.is_win() and "dll" or "so") - if not vim.uv.fs_stat(lib) then - LazyVim.warn("`telescope-fzf-native.nvim` not built. Rebuilding...") - require("lazy").build({ plugins = { plugin }, show = false }):wait(function() - LazyVim.info("Rebuilding `telescope-fzf-native.nvim` done.\nPlease restart Neovim.") - end) - else - LazyVim.error("Failed to load `telescope-fzf-native.nvim`:\n" .. err) - end - end - end) - end, + desc = "Fast and modern file picker", + { "folke/snacks.nvim", + opts = { + picker = { + win = { + input = { + keys = { + [""] = { "trouble_open", mode = { "n", "i" }, }, + }, + }, + }, + actions = { + actions = require("trouble.sources.snacks").actions, + }, }, }, + -- stylua: ignore keys = { - -- from lazyvim - { ",", "Telescope buffers show_all_buffers=true", desc = "Switch Buffer" }, - { "/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, - { ":", "Telescope command_history", desc = "Command History" }, - -- { "", LazyVim.pick("files"), desc = "Find Files (Root Dir)" }, - { "", false }, + { ",", function() Snacks.picker.buffers() end, desc = "Buffers" }, + { "/", function() Snacks.picker.grep() end, desc = "Grep" }, + { ":", function() Snacks.picker.command_history() end, desc = "Command History" }, + { "n", function() Snacks.picker.notifications() end, desc = "Notification History" }, -- find - { - "fb", - "Telescope buffers sort_mru=true sort_lastused=true ignore_current_buffer=true", - desc = "Buffers", - }, - { "fc", LazyVim.pick.config_files(), desc = "Find Config File" }, - -- { "ff", LazyVim.pick("files"), desc = "Find Files (root dir)" }, - { "ff", false }, -- fswitch - { "fF", LazyVim.pick("files", { root = false }), desc = "Find Files (cwd)" }, - { "fg", "Telescope git_files", desc = "Find Files (git-files)" }, - { "fr", "Telescope oldfiles", desc = "Recent" }, - { "fR", LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" }, + { "fb", function() Snacks.picker.buffers() end, desc = "Buffers" }, + { "fB", function() Snacks.picker.buffers({ hidden = true, nofile = true }) end, desc = "Buffers (all)" }, + { "fc", function() Snacks.picker.files({ cwd = vim.fn.stdpath("config") }) end, desc = "Find Config File" }, + { "fF", function() Snacks.picker.files() end, desc = "Find Files" }, + { "fg", function() Snacks.picker.git_files() end, desc = "Find Files (git-files)" }, + -- TODO: swap fr and fR ? + { "fr", function() Snacks.picker.recent() end, desc = "Recent" }, + { "fR", function() Snacks.picker.recent({ filter = { cwd = true }}) end, desc = "Recent (cwd)" }, + { "fp", function() Snacks.picker.projects() end, desc = "Projects" }, -- git - -- { "gc", "Telescope git_commits", desc = "Commits" }, - -- { "gs", "Telescope git_status", desc = "Status" }, - { "gc", false }, - { "gs", false }, + -- { "gc", function() Snacks.picker.git_log() end, desc = "Git Log" }, + -- { "gd", function() Snacks.picker.git_diff() end, desc = "Git Diff (hunks)" }, + -- { "gs", function() Snacks.picker.git_status() end, desc = "Git Status" }, + -- Grep + { "sb", function() Snacks.picker.lines() end, desc = "Buffer Lines" }, + { "sB", function() Snacks.picker.grep_buffers() end, desc = "Grep Open Buffers" }, + { "sg", function() Snacks.picker.grep() end, desc = "Grep" }, + { "sp", function() Snacks.picker.lazy() end, desc = "Search for Plugin Spec" }, + { "sw", function() Snacks.picker.grep_word() end, desc = "Visual selection or word", mode = { "n", "x" } }, -- search - { 's"', "Telescope registers", desc = "Registers" }, - { "sa", "Telescope autocommands", desc = "Auto Commands" }, - { "sb", "Telescope current_buffer_fuzzy_find", desc = "Buffer" }, - { "sc", "Telescope command_history", desc = "Command History" }, - { "sC", "Telescope commands", desc = "Commands" }, - { "sd", "Telescope diagnostics bufnr=0", desc = "Document Diagnostics" }, - { "sD", "Telescope diagnostics", desc = "Workspace Diagnostics" }, - { "sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" }, - { "sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" }, - { "sh", "Telescope help_tags", desc = "Help Pages" }, - { "sH", "Telescope highlights", desc = "Search Highlight Groups" }, - { "sj", "Telescope jumplist", desc = "Jumplist" }, - { "sk", "Telescope keymaps", desc = "Key Maps" }, - { "sl", "Telescope loclist", desc = "Location List" }, - { "sM", "Telescope man_pages", desc = "Man Pages" }, - { "sm", "Telescope marks", desc = "Jump to Mark" }, - { "so", "Telescope vim_options", desc = "Options" }, - { "sR", "Telescope resume", desc = "Resume" }, - { "sq", "Telescope quickfix", desc = "Quickfix List" }, - { "sw", LazyVim.pick("grep_string", { word_match = "-w" }), desc = "Word (Root Dir)" }, - { "sW", LazyVim.pick("grep_string", { root = false, word_match = "-w" }), desc = "Word (cwd)" }, - { "sw", LazyVim.pick("grep_string"), mode = "v", desc = "Selection (Root Dir)" }, - { "sW", LazyVim.pick("grep_string", { root = false }), mode = "v", desc = "Selection (cwd)" }, - { "uC", LazyVim.pick("colorscheme", { enable_preview = true }), desc = "Colorscheme with Preview" }, - -- { - -- "ss", - -- LazyVim.pick("lsp_document_symbols", { - -- symbols = { - -- "Class", - -- "Function", - -- "Method", - -- "Constructor", - -- "Interface", - -- "Module", - -- "Struct", - -- "Trait", - -- "Field", - -- "Property", - -- }, - -- }), - -- desc = "Goto Symbol", - -- }, - { "ss", false }, -- use for snippets below - { - "sS", - LazyVim.pick("lsp_dynamic_workspace_symbols", { - symbols = { - "Class", - "Function", - "Method", - "Constructor", - "Interface", - "Module", - "Struct", - "Trait", - "Field", - "Property", - }, - }), - desc = "Goto Symbol (Workspace)", - }, + { 's"', function() Snacks.picker.registers() end, desc = "Registers" }, + { "sa", function() Snacks.picker.autocmds() end, desc = "Autocmds" }, + { "sc", function() Snacks.picker.command_history() end, desc = "Command History" }, + { "sC", function() Snacks.picker.commands() end, desc = "Commands" }, + { "sd", function() Snacks.picker.diagnostics() end, desc = "Diagnostics" }, + { "sh", function() Snacks.picker.help() end, desc = "Help Pages" }, + { "sH", function() Snacks.picker.highlights() end, desc = "Highlights" }, + { "si", function() Snacks.picker.icons() end, desc = "Icons" }, + { "sj", function() Snacks.picker.jumps() end, desc = "Jumps" }, + { "sk", function() Snacks.picker.keymaps() end, desc = "Keymaps" }, + { "sl", function() Snacks.picker.loclist() end, desc = "Location List" }, + { "sM", function() Snacks.picker.man() end, desc = "Man Pages" }, + { "sm", function() Snacks.picker.marks() end, desc = "Marks" }, + { "sR", function() Snacks.picker.resume() end, desc = "Resume" }, + { "sq", function() Snacks.picker.qflist() end, desc = "Quickfix List" }, + { "su", function() Snacks.picker.undo() end, desc = "Undotree" }, + -- ui + { "uC", function() Snacks.picker.colorschemes() end, desc = "Colorschemes" }, }, - opts = function() - local actions = require("telescope.actions") - - local open_with_trouble = function(...) - return require("trouble.sources.telescope").open(...) - end - local find_files_no_ignore = function() - local action_state = require("telescope.actions.state") - local line = action_state.get_current_line() - LazyVim.pick("find_files", { no_ignore = true, default_text = line })() - end - local find_files_with_hidden = function() - local action_state = require("telescope.actions.state") - local line = action_state.get_current_line() - LazyVim.pick("find_files", { hidden = true, default_text = line })() - end - - local function find_command() - if 1 == vim.fn.executable("rg") then - return { "rg", "--files", "--color", "never", "-g", "!.git" } - elseif 1 == vim.fn.executable("fd") then - return { "fd", "--type", "f", "--color", "never", "-E", ".git" } - elseif 1 == vim.fn.executable("fdfind") then - return { "fdfind", "--type", "f", "--color", "never", "-E", ".git" } - elseif 1 == vim.fn.executable("find") and vim.fn.has("win32") == 0 then - return { "find", ".", "-type", "f" } - elseif 1 == vim.fn.executable("where") then - return { "where", "/r", ".", "*" } - end - end - - return { - defaults = { - prompt_prefix = " ", - selection_caret = " ", - -- open files in the first window that is an actual file. - -- use the current window if no other window is available. - get_selection_window = function() - local wins = vim.api.nvim_list_wins() - table.insert(wins, 1, vim.api.nvim_get_current_win()) - for _, win in ipairs(wins) do - local buf = vim.api.nvim_win_get_buf(win) - if vim.bo[buf].buftype == "" then - return win - end - end - return 0 - end, - mappings = { - i = { - [""] = open_with_trouble, - [""] = open_with_trouble, - [""] = find_files_no_ignore, - [""] = find_files_with_hidden, - [""] = actions.cycle_history_next, - [""] = actions.cycle_history_prev, - [""] = actions.preview_scrolling_down, - [""] = actions.preview_scrolling_up, - }, - n = { - ["q"] = actions.close, - }, - }, - }, - pickers = { - find_files = { - find_command = find_command, - hidden = true, - }, - }, - } - end, }, - - -- Flash Telescope config - { - "nvim-telescope/telescope.nvim", - optional = true, - opts = function(_, opts) - if not LazyVim.has("flash.nvim") then - return - end - local function flash(prompt_bufnr) - require("flash").jump({ - pattern = "^", - label = { after = { 0, 0 } }, - search = { - mode = "search", - exclude = { - function(win) - return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "TelescopeResults" - end, - }, - }, - action = function(match) - local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr) - picker:set_selection(match.pos[1] - 1) - end, - }) - end - opts.defaults = vim.tbl_deep_extend("force", opts.defaults or {}, { - mappings = { n = { s = flash }, i = { [""] = flash } }, - }) - end, - }, - - -- better vim.ui with telescope - { - "stevearc/dressing.nvim", - lazy = true, - enabled = function() - return LazyVim.pick.want() == "telescope" - end, - init = function() - ---@diagnostic disable-next-line: duplicate-set-field - vim.ui.select = function(...) - require("lazy").load({ plugins = { "dressing.nvim" } }) - return vim.ui.select(...) - end - ---@diagnostic disable-next-line: duplicate-set-field - vim.ui.input = function(...) - require("lazy").load({ plugins = { "dressing.nvim" } }) - return vim.ui.input(...) - end - end, - }, - - { - "neovim/nvim-lspconfig", + { "neovim/nvim-lspconfig", opts = function() - if LazyVim.pick.want() ~= "telescope" then - return - end local Keys = require("lazyvim.plugins.lsp.keymaps").get() -- stylua: ignore vim.list_extend(Keys, { - { "gd", function() require("telescope.builtin").lsp_definitions({ reuse_win = true }) end, desc = "Goto Definition", has = "definition" }, - { "gr", "Telescope lsp_references", desc = "References", nowait = true }, - { "gI", function() require("telescope.builtin").lsp_implementations({ reuse_win = true }) end, desc = "Goto Implementation" }, - { "gy", function() require("telescope.builtin").lsp_type_definitions({ reuse_win = true }) end, desc = "Goto T[y]pe Definition" }, + { "gd", function() Snacks.picker.lsp_definitions() end, desc = "Goto Definition", has = "definition" }, + -- { "gr", function() Snacks.picker.lsp_references() end, nowait = true, desc = "References" }, + { "gI", function() Snacks.picker.lsp_implementations() end, desc = "Goto Implementation" }, + { "gy", function() Snacks.picker.lsp_type_definitions() end, desc = "Goto T[y]pe Definition" }, + { "ss", function() Snacks.picker.lsp_symbols({ filter = LazyVim.config.kind_filter }) end, desc = "LSP Symbols", has = "documentSymbol" }, + { "sS", function() Snacks.picker.lsp_workspace_symbols({ filter = LazyVim.config.kind_filter }) end, desc = "LSP Workspace Symbols", has = "workspace/symbols" }, }) end, }, - - { - "benfowler/telescope-luasnip.nvim", - dependencies = { - "telescope.nvim", + { "folke/todo-comments.nvim", + optional = true, + -- stylua: ignore + keys = { + { "st", function() Snacks.picker.todo_comments() end, desc = "Todo" }, + { "sT", function () Snacks.picker.todo_comments({ keywords = { "TODO", "FIX", "FIXME" } }) end, desc = "Todo/Fix/Fixme" }, + }, + }, + { "folke/flash.nvim", + -- TODO: verify if I want to keep this + specs = { + { + "folke/snacks.nvim", + opts = { + picker = { + win = { + input = { + keys = { + [""] = { "flash", mode = { "n", "i" } }, + ["s"] = { "flash" }, + }, + }, + }, + actions = { + flash = function(picker) + require("flash").jump({ + pattern = "^", + label = { after = { 0, 0 } }, + search = { + mode = "search", + exclude = { + function(win) + return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "snacks_picker_list" + end, + }, + }, + action = function(match) + local idx = picker.list:row2idx(match.pos[1]) + picker.list:_move(idx, true, true) + end, + }) + end, + }, + }, + }, + }, }, - config = function() - require("telescope").load_extension("luasnip") - end, - keys = { { "ss", "Telescope luasnip", desc = "Snippets" } }, }, }