local function project_files() require("telescope.builtin").find_files({ cwd = require("lspconfig.util").root_pattern(".git")(vim.fn.expand("%:p")), }) end local M = { "nvim-telescope/telescope.nvim", lazy = false, dependencies = { "nvim-lua/popup.nvim", "nvim-lua/plenary.nvim", "nvim-telescope/telescope-fzy-native.nvim", "nvim-telescope/telescope-github.nvim", "nvim-telescope/telescope-dap.nvim", "nvim-telescope/telescope-ui-select.nvim", }, } function M.config() local telescope = require("telescope") local actions = require("telescope.actions") local previewers = require("telescope.previewers") vim.keymap.set("n", "b", 'lua require("telescope.builtin").buffers()') vim.keymap.set("n", "f", 'lua require("telescope.builtin").oldfiles()') vim.keymap.set("n", "", 'lua require("telescope.builtin").oldfiles({cwd_only=true})') vim.keymap.set("n", "", 'lua require("telescope.builtin").oldfiles()') vim.keymap.set("n", "d", 'lua require("telescope.builtin").diagnostics()') vim.keymap.set("n", "e", 'lua require("telescope.builtin").git_files()') vim.keymap.set("n", "g", 'lua require("telescope.builtin").git_status()') vim.keymap.set("n", "a", 'lua require("telescope.builtin").lsp_code_actions()') vim.keymap.set("n", "m", 'lua require("telescope.builtin").marks()') vim.keymap.set("n", "s", 'lua require("telescope.builtin").lsp_document_symbols()') vim.keymap.set("n", "t", 'lua require("telescope.builtin").treesitter()') vim.keymap.set("n", "/", 'lua require("telescope.builtin").live_grep()') vim.keymap.set("n", ".", 'lua require("telescope.builtin").file_browser()') vim.keymap.set("n", "p", 'lua require("telescope.builtin").registers()') vim.keymap.set("n", "ga", "lua vim.lsp.buf.code_action()") vim.keymap.set("n", "gr", 'lua require("telescope.builtin").lsp_references()') vim.keymap.set("n", "gd", 'lua require("telescope.builtin").lsp_definitions()') vim.keymap.set("n", "g/", 'lua require("telescope.builtin").lsp_document_symbols()') vim.keymap.set( "n", "g?", 'lua require("telescope.builtin").lsp_workspace_symbols({query=(vim.bo.filetype == "go" and "\'" or "")})' ) vim.keymap.set("n", "ge", 'lua require("telescope.builtin").lsp_document_diagnostics()') vim.keymap.set("n", "Db", 'lua require("telescope").extensions.dap.list_breakpoints()') vim.keymap.set("n", "Dcc", 'lua require("telescope").extensions.dap.commands()') vim.keymap.set("n", "Df", 'lua require("telescope").extensions.dap.frames()') vim.keymap.set("n", "Dv", 'lua require("telescope").extensions.dap.variables()') -- Setup telescope.setup({ defaults = { layout_strategy = "flex", -- layout_defaults = {flip_columns = 160}, layout_config = { preview_cutoff = 10, prompt_position = "bottom", mirror = true, }, mappings = { i = { [""] = actions.select_default + actions.center, [""] = actions.close, [""] = actions.add_selection, }, }, color_devicons = true, file_previewer = previewers.vim_buffer_cat.new, grep_previewer = previewers.vim_buffer_vimgrep.new, qflist_previewer = previewers.vim_buffer_qflist.new, }, extensions = { ["ui-select"] = { require("telescope.themes").get_dropdown({ -- even more opts }), }, }, }) local layout_strategies = require("telescope.pickers.layout_strategies") local config = require("telescope.config") layout_strategies.flex = function(self, max_columns, max_lines) local layout_config = self.layout_config or {} local flip_columns = layout_config.flip_columns or 160 -- Here's why. local flip_lines = layout_config.flip_lines or 20 if max_columns < flip_columns and max_lines > flip_lines then self.layout_config = (config.values.layout_defaults or {})["vertical"] return layout_strategies.vertical(self, max_columns, max_lines) else self.layout_config = (config.values.layout_defaults or {})["horizontal"] return layout_strategies.horizontal(self, max_columns, max_lines) end end -- Extensions telescope.load_extension("dap") telescope.load_extension("fzy_native") telescope.load_extension("gh") telescope.load_extension("ui-select") end return M