telescope.lua 5.5 KB

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