telescope.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 = { mirror = false },
  26. vertical = { mirror = false },
  27. },
  28. vimgrep_arguments = {
  29. "rg",
  30. "--color=never",
  31. "--no-heading",
  32. "--with-filename",
  33. "--line-number",
  34. "--column",
  35. "--smart-case",
  36. "--hidden",
  37. "--glob=!.git/",
  38. },
  39. mappings = {
  40. i = {
  41. ["<C-n>"] = actions.move_selection_next,
  42. ["<C-p>"] = actions.move_selection_previous,
  43. ["<C-c>"] = actions.close,
  44. ["<C-j>"] = actions.cycle_history_next,
  45. ["<C-k>"] = actions.cycle_history_prev,
  46. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  47. ["<CR>"] = actions.select_default + actions.center,
  48. },
  49. n = {
  50. ["<C-n>"] = actions.move_selection_next,
  51. ["<C-p>"] = actions.move_selection_previous,
  52. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  53. },
  54. },
  55. file_ignore_patterns = {},
  56. path_display = { shorten = 5 },
  57. winblend = 0,
  58. border = {},
  59. borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
  60. color_devicons = true,
  61. set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
  62. pickers = {
  63. find_files = {
  64. find_command = { "fd", "--type=file", "--hidden", "--smart-case" },
  65. },
  66. live_grep = {
  67. --@usage don't include the filename in the search results
  68. only_sort_text = true,
  69. },
  70. },
  71. },
  72. extensions = {
  73. fzf = {
  74. fuzzy = true, -- false will only do exact matching
  75. override_generic_sorter = true, -- override the generic sorter
  76. override_file_sorter = true, -- override the file sorter
  77. case_mode = "smart_case", -- or "ignore_case" or "respect_case"
  78. },
  79. },
  80. })
  81. end
  82. function M.code_actions()
  83. local opts = {
  84. winblend = 15,
  85. layout_config = {
  86. prompt_position = "top",
  87. width = 80,
  88. height = 12,
  89. },
  90. borderchars = {
  91. prompt = { "─", "│", " ", "│", "╭", "╮", "│", "│" },
  92. results = { "─", "│", "─", "│", "├", "┤", "╯", "╰" },
  93. preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
  94. },
  95. border = {},
  96. previewer = false,
  97. shorten_path = false,
  98. }
  99. local builtin = require "telescope.builtin"
  100. local themes = require "telescope.themes"
  101. builtin.lsp_code_actions(themes.get_dropdown(opts))
  102. end
  103. function M.setup()
  104. local previewers = require "telescope.previewers"
  105. local sorters = require "telescope.sorters"
  106. local actions = require "telescope.actions"
  107. lvim.builtin.telescope = vim.tbl_extend("keep", {
  108. file_previewer = previewers.vim_buffer_cat.new,
  109. grep_previewer = previewers.vim_buffer_vimgrep.new,
  110. qflist_previewer = previewers.vim_buffer_qflist.new,
  111. file_sorter = sorters.get_fuzzy_file,
  112. generic_sorter = sorters.get_generic_fuzzy_sorter,
  113. ---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults.
  114. mappings = {
  115. i = {
  116. ["<C-n>"] = actions.move_selection_next,
  117. ["<C-p>"] = actions.move_selection_previous,
  118. ["<C-c>"] = actions.close,
  119. ["<C-j>"] = actions.cycle_history_next,
  120. ["<C-k>"] = actions.cycle_history_prev,
  121. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  122. ["<CR>"] = actions.select_default + actions.center,
  123. },
  124. n = {
  125. ["<C-n>"] = actions.move_selection_next,
  126. ["<C-p>"] = actions.move_selection_previous,
  127. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  128. },
  129. },
  130. }, lvim.builtin.telescope)
  131. local telescope = require "telescope"
  132. telescope.setup(lvim.builtin.telescope)
  133. if lvim.builtin.project.active then
  134. pcall(function()
  135. require("telescope").load_extension "projects"
  136. end)
  137. end
  138. if lvim.builtin.telescope.on_config_done then
  139. lvim.builtin.telescope.on_config_done(telescope)
  140. end
  141. if lvim.builtin.telescope.extensions and lvim.builtin.telescope.extensions.fzf then
  142. require("telescope").load_extension "fzf"
  143. end
  144. end
  145. return M