telescope.lua 4.9 KB

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