From 688587e9ab39438d038e473aa51622785b7ce9ac Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sat, 10 Sep 2022 12:08:37 +0200 Subject: [PATCH] nvim: clean up telescope config --- .config/nvim/lua/dln/telescope.lua | 60 ------------------- .config/nvim/lua/plugins.lua | 24 +------- .config/nvim/lua/plugins/telescope.lua | 82 ++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 83 deletions(-) delete mode 100644 .config/nvim/lua/dln/telescope.lua create mode 100644 .config/nvim/lua/plugins/telescope.lua diff --git a/.config/nvim/lua/dln/telescope.lua b/.config/nvim/lua/dln/telescope.lua deleted file mode 100644 index c25f691..0000000 --- a/.config/nvim/lua/dln/telescope.lua +++ /dev/null @@ -1,60 +0,0 @@ -local telescope = require("telescope") -local actions = require("telescope.actions") -local previewers = require("telescope.previewers") - --- Setup -telescope.setup { - defaults = { - layout_strategy = "flex", - -- layout_defaults = {flip_columns = 160}, - layout_config = { - preview_cutoff = 10, - }, - 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 - } -} - -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("packer") -- currently breaking packer - -local M = {} - --- Pickers -M.project_files = function() - require("telescope.builtin").find_files { - cwd = require("lspconfig.util").root_pattern(".git")(vim.fn.expand("%:p")) - } -end - -return M diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 1b6178f..2013412 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -151,29 +151,7 @@ return require("packer").startup(function() "nvim-telescope/telescope-dap.nvim", }, config = function() - require("dln.telescope") - local map = require("dln.utils").map - map("n", "b", 'lua require("telescope.builtin").buffers()') - map("n", "f", 'lua require("telescope.builtin").oldfiles()') - map("n", "", 'lua require("telescope.builtin").oldfiles()') - map("n", "e", 'lua require("telescope.builtin").git_files()') - map("n", "g", 'lua require("telescope.builtin").git_status()') - map("n", "a", 'lua require("telescope.builtin").lsp_code_actions()') - map("n", "m", 'lua require("telescope.builtin").marks()') - map("n", "s", 'lua require("telescope.builtin").lsp_document_symbols()') - map("n", "t", 'lua require("telescope.builtin").treesitter()') - map("n", "/", 'lua require("telescope.builtin").live_grep()') - map("n", ".", 'lua require("telescope.builtin").file_browser()') - map("n", "p", 'lua require("telescope.builtin").registers()') - map("n", "gr", 'lua require("telescope.builtin").lsp_references()') - map("n", "gd", 'lua require("telescope.builtin").lsp_definitions()') - map("n", "g/", 'lua require("telescope.builtin").lsp_document_symbols()') - map("n", "g?", 'lua require("telescope.builtin").lsp_workspace_symbols()') - map("n", "ge", 'lua require("telescope.builtin").lsp_document_diagnostics()') - map("n", "Db", 'lua require("telescope").extensions.dap.list_breakpoints()') - map("n", "Dcc", 'lua require("telescope").extensions.dap.commands()') - map("n", "Df", 'lua require("telescope").extensions.dap.frames()') - map("n", "Dv", 'lua require("telescope").extensions.dap.variables()') + require("plugins/telescope") end, }) diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..7b28aec --- /dev/null +++ b/.config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,82 @@ +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()') +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", "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()') +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, + }, + 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, + }, +}) + +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("packer") -- currently breaking packer + +local M = {} + +-- Pickers +M.project_files = function() + require("telescope.builtin").find_files({ + cwd = require("lspconfig.util").root_pattern(".git")(vim.fn.expand("%:p")), + }) +end + +return M