telescope.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. local M = {}
  2. local pickers = {
  3. find_files = {
  4. theme = "dropdown",
  5. hidden = true,
  6. previewer = false,
  7. },
  8. live_grep = {
  9. --@usage don't include the filename in the search results
  10. only_sort_text = true,
  11. theme = "dropdown",
  12. },
  13. grep_string = {
  14. only_sort_text = true,
  15. theme = "dropdown",
  16. },
  17. buffers = {
  18. theme = "dropdown",
  19. previewer = false,
  20. initial_mode = "normal",
  21. },
  22. planets = {
  23. show_pluto = true,
  24. show_moon = true,
  25. },
  26. git_files = {
  27. theme = "dropdown",
  28. hidden = true,
  29. previewer = false,
  30. show_untracked = true,
  31. },
  32. lsp_references = {
  33. theme = "dropdown",
  34. initial_mode = "normal",
  35. },
  36. lsp_definitions = {
  37. theme = "dropdown",
  38. initial_mode = "normal",
  39. },
  40. lsp_declarations = {
  41. theme = "dropdown",
  42. initial_mode = "normal",
  43. },
  44. lsp_implementations = {
  45. theme = "dropdown",
  46. initial_mode = "normal",
  47. },
  48. }
  49. function M.config()
  50. -- Define this minimal config so that it's available if telescope is not yet available.
  51. lvim.builtin.telescope = {
  52. ---@usage disable telescope completely [not recommended]
  53. active = true,
  54. on_config_done = nil,
  55. }
  56. local ok, actions = pcall(require, "telescope.actions")
  57. if not ok then
  58. return
  59. end
  60. lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
  61. defaults = {
  62. prompt_prefix = lvim.icons.ui.Telescope .. " ",
  63. selection_caret = lvim.icons.ui.Forward .. " ",
  64. entry_prefix = " ",
  65. initial_mode = "insert",
  66. selection_strategy = "reset",
  67. sorting_strategy = "descending",
  68. layout_strategy = "horizontal",
  69. layout_config = {
  70. width = 0.75,
  71. preview_cutoff = 120,
  72. horizontal = {
  73. preview_width = function(_, cols, _)
  74. if cols < 120 then
  75. return math.floor(cols * 0.5)
  76. end
  77. return math.floor(cols * 0.6)
  78. end,
  79. mirror = false,
  80. },
  81. vertical = { mirror = false },
  82. },
  83. vimgrep_arguments = {
  84. "rg",
  85. "--color=never",
  86. "--no-heading",
  87. "--with-filename",
  88. "--line-number",
  89. "--column",
  90. "--smart-case",
  91. "--hidden",
  92. "--glob=!.git/",
  93. },
  94. mappings = {
  95. i = {
  96. ["<C-n>"] = actions.move_selection_next,
  97. ["<C-p>"] = actions.move_selection_previous,
  98. ["<C-c>"] = actions.close,
  99. ["<C-j>"] = actions.cycle_history_next,
  100. ["<C-k>"] = actions.cycle_history_prev,
  101. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  102. ["<CR>"] = actions.select_default,
  103. ["<C-d>"] = require("telescope.actions").delete_buffer,
  104. },
  105. n = {
  106. ["<C-n>"] = actions.move_selection_next,
  107. ["<C-p>"] = actions.move_selection_previous,
  108. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  109. ["dd"] = require("telescope.actions").delete_buffer,
  110. },
  111. },
  112. pickers = pickers,
  113. file_ignore_patterns = {},
  114. path_display = { "smart" },
  115. winblend = 0,
  116. border = {},
  117. borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
  118. color_devicons = true,
  119. set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
  120. },
  121. pickers = pickers,
  122. extensions = {
  123. fzf = {
  124. fuzzy = true, -- false will only do exact matching
  125. override_generic_sorter = true, -- override the generic sorter
  126. override_file_sorter = true, -- override the file sorter
  127. case_mode = "smart_case", -- or "ignore_case" or "respect_case"
  128. },
  129. },
  130. })
  131. end
  132. function M.setup()
  133. local previewers = require "telescope.previewers"
  134. local sorters = require "telescope.sorters"
  135. local actions = require "telescope.actions"
  136. lvim.builtin.telescope = vim.tbl_extend("keep", {
  137. file_previewer = previewers.vim_buffer_cat.new,
  138. grep_previewer = previewers.vim_buffer_vimgrep.new,
  139. qflist_previewer = previewers.vim_buffer_qflist.new,
  140. file_sorter = sorters.get_fuzzy_file,
  141. generic_sorter = sorters.get_generic_fuzzy_sorter,
  142. ---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults.
  143. mappings = {
  144. i = {
  145. ["<C-n>"] = actions.move_selection_next,
  146. ["<C-p>"] = actions.move_selection_previous,
  147. ["<C-c>"] = actions.close,
  148. ["<C-j>"] = actions.cycle_history_next,
  149. ["<C-k>"] = actions.cycle_history_prev,
  150. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  151. ["<CR>"] = actions.select_default + actions.center,
  152. },
  153. n = {
  154. ["<C-n>"] = actions.move_selection_next,
  155. ["<C-p>"] = actions.move_selection_previous,
  156. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  157. ["dd"] = require("telescope.actions").delete_buffer,
  158. },
  159. },
  160. }, lvim.builtin.telescope)
  161. local telescope = require "telescope"
  162. telescope.setup(lvim.builtin.telescope)
  163. if lvim.builtin.project.active then
  164. pcall(function()
  165. require("telescope").load_extension "projects"
  166. end)
  167. end
  168. if lvim.builtin.notify.active then
  169. pcall(function()
  170. require("telescope").load_extension "notify"
  171. end)
  172. end
  173. if lvim.builtin.telescope.on_config_done then
  174. lvim.builtin.telescope.on_config_done(telescope)
  175. end
  176. if lvim.builtin.telescope.extensions and lvim.builtin.telescope.extensions.fzf then
  177. pcall(function()
  178. require("telescope").load_extension "fzf"
  179. end)
  180. end
  181. end
  182. return M