telescope.lua 4.7 KB

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