Przeglądaj źródła

feat(telescope): add `lvim.builtin.telescope.theme` (#3548)

fixes https://github.com/LunarVim/LunarVim/issues/3406
LostNeophyte 2 lat temu
rodzic
commit
245a71c9f7
2 zmienionych plików z 58 dodań i 80 usunięć
  1. 51 78
      lua/lvim/core/telescope.lua
  2. 7 2
      lua/lvim/core/which-key.lua

+ 51 - 78
lua/lvim/core/telescope.lua

@@ -1,62 +1,10 @@
 local M = {}
 
-local function get_pickers(actions)
-  return {
-    find_files = {
-      theme = "dropdown",
-      hidden = true,
-      previewer = false,
-    },
-    live_grep = {
-      --@usage don't include the filename in the search results
-      only_sort_text = true,
-      theme = "dropdown",
-    },
-    grep_string = {
-      only_sort_text = true,
-      theme = "dropdown",
-    },
-    buffers = {
-      theme = "dropdown",
-      previewer = false,
-      initial_mode = "normal",
-      mappings = {
-        i = {
-          ["<C-d>"] = actions.delete_buffer,
-        },
-        n = {
-          ["dd"] = actions.delete_buffer,
-        },
-      },
-    },
-    planets = {
-      show_pluto = true,
-      show_moon = true,
-    },
-    git_files = {
-      theme = "dropdown",
-      hidden = true,
-      previewer = false,
-      show_untracked = true,
-    },
-    lsp_references = {
-      theme = "dropdown",
-      initial_mode = "normal",
-    },
-    lsp_definitions = {
-      theme = "dropdown",
-      initial_mode = "normal",
-    },
-    lsp_declarations = {
-      theme = "dropdown",
-      initial_mode = "normal",
-    },
-    lsp_implementations = {
-      theme = "dropdown",
-      initial_mode = "normal",
-    },
-  }
-end
+---@alias telescope_themes
+---| "cursor"   # see `telescope.themes.get_cursor()`
+---| "dropdown" # see `telescope.themes.get_dropdown()`
+---| "ivy"      # see `telescope.themes.get_ivy()`
+---| "center"   # retain the default telescope theme
 
 function M.config()
   -- Define this minimal config so that it's available if telescope is not yet available.
@@ -71,29 +19,19 @@ function M.config()
   if not ok then
     return
   end
-  lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
+  lvim.builtin.telescope = {
+    active = true,
+    on_config_done = nil,
+    theme = "dropdown", ---@type telescope_themes
     defaults = {
       prompt_prefix = lvim.icons.ui.Telescope .. " ",
       selection_caret = lvim.icons.ui.Forward .. " ",
       entry_prefix = "  ",
       initial_mode = "insert",
       selection_strategy = "reset",
-      sorting_strategy = "descending",
-      layout_strategy = "horizontal",
-      layout_config = {
-        width = 0.75,
-        preview_cutoff = 120,
-        horizontal = {
-          preview_width = function(_, cols, _)
-            if cols < 120 then
-              return math.floor(cols * 0.5)
-            end
-            return math.floor(cols * 0.6)
-          end,
-          mirror = false,
-        },
-        vertical = { mirror = false },
-      },
+      sorting_strategy = nil,
+      layout_strategy = nil,
+      layout_config = nil,
       vimgrep_arguments = {
         "rg",
         "--color=never",
@@ -122,16 +60,45 @@ function M.config()
           ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
         },
       },
-      pickers = get_pickers(actions),
       file_ignore_patterns = {},
       path_display = { "smart" },
       winblend = 0,
       border = {},
-      borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
+      borderchars = nil,
       color_devicons = true,
       set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
     },
-    pickers = get_pickers(actions),
+    pickers = {
+      find_files = {
+        hidden = true,
+      },
+      live_grep = {
+        --@usage don't include the filename in the search results
+        only_sort_text = true,
+      },
+      grep_string = {
+        only_sort_text = true,
+      },
+      buffers = {
+        initial_mode = "normal",
+        mappings = {
+          i = {
+            ["<C-d>"] = actions.delete_buffer,
+          },
+          n = {
+            ["dd"] = actions.delete_buffer,
+          },
+        },
+      },
+      planets = {
+        show_pluto = true,
+        show_moon = true,
+      },
+      git_files = {
+        hidden = true,
+        show_untracked = true,
+      },
+    },
     extensions = {
       fzf = {
         fuzzy = true, -- false will only do exact matching
@@ -140,7 +107,7 @@ function M.config()
         case_mode = "smart_case", -- or "ignore_case" or "respect_case"
       },
     },
-  })
+  }
 end
 
 function M.setup()
@@ -156,6 +123,12 @@ function M.setup()
   }, lvim.builtin.telescope)
 
   local telescope = require "telescope"
+
+  local theme = require("telescope.themes")["get_" .. lvim.builtin.telescope.theme]
+  if theme then
+    lvim.builtin.telescope.defaults = theme(lvim.builtin.telescope.defaults)
+  end
+
   telescope.setup(lvim.builtin.telescope)
 
   if lvim.builtin.project.active then

+ 7 - 2
lua/lvim/core/which-key.lua

@@ -84,13 +84,18 @@ M.config = function()
       ["q"] = { "<cmd>lua require('lvim.utils.functions').smart_quit()<CR>", "Quit" },
       ["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" },
       ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },
-      ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" },
+      ["f"] = {
+        function()
+          require("lvim.core.telescope.custom-finders").find_project_files { previewer = false }
+        end,
+        "Find File",
+      },
       ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
       ["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" },
       b = {
         name = "Buffers",
         j = { "<cmd>BufferLinePick<cr>", "Jump" },
-        f = { "<cmd>Telescope buffers<cr>", "Find" },
+        f = { "<cmd>Telescope buffers previewer=false<cr>", "Find" },
         b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" },
         n = { "<cmd>BufferLineCycleNext<cr>", "Next" },
         W = { "<cmd>noautocmd w<cr>", "Save without formatting (noautocmd)" },