telescope.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. },
  57. n = {
  58. ["<C-n>"] = actions.move_selection_next,
  59. ["<C-p>"] = actions.move_selection_previous,
  60. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  61. },
  62. },
  63. file_ignore_patterns = {},
  64. path_display = { shorten = 5 },
  65. winblend = 0,
  66. border = {},
  67. borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
  68. color_devicons = true,
  69. set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
  70. },
  71. pickers = {
  72. find_files = {
  73. hidden = true,
  74. },
  75. live_grep = {
  76. --@usage don't include the filename in the search results
  77. only_sort_text = true,
  78. },
  79. },
  80. extensions = {
  81. fzf = {
  82. fuzzy = true, -- false will only do exact matching
  83. override_generic_sorter = true, -- override the generic sorter
  84. override_file_sorter = true, -- override the file sorter
  85. case_mode = "smart_case", -- or "ignore_case" or "respect_case"
  86. },
  87. },
  88. })
  89. end
  90. function M.setup()
  91. local previewers = require "telescope.previewers"
  92. local sorters = require "telescope.sorters"
  93. local actions = require "telescope.actions"
  94. lvim.builtin.telescope = vim.tbl_extend("keep", {
  95. file_previewer = previewers.vim_buffer_cat.new,
  96. grep_previewer = previewers.vim_buffer_vimgrep.new,
  97. qflist_previewer = previewers.vim_buffer_qflist.new,
  98. file_sorter = sorters.get_fuzzy_file,
  99. generic_sorter = sorters.get_generic_fuzzy_sorter,
  100. ---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults.
  101. mappings = {
  102. i = {
  103. ["<C-n>"] = actions.move_selection_next,
  104. ["<C-p>"] = actions.move_selection_previous,
  105. ["<C-c>"] = actions.close,
  106. ["<C-j>"] = actions.cycle_history_next,
  107. ["<C-k>"] = actions.cycle_history_prev,
  108. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  109. ["<CR>"] = actions.select_default + actions.center,
  110. },
  111. n = {
  112. ["<C-n>"] = actions.move_selection_next,
  113. ["<C-p>"] = actions.move_selection_previous,
  114. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  115. },
  116. },
  117. }, lvim.builtin.telescope)
  118. local telescope = require "telescope"
  119. telescope.setup(lvim.builtin.telescope)
  120. if lvim.builtin.project.active then
  121. pcall(function()
  122. require("telescope").load_extension "projects"
  123. end)
  124. end
  125. if lvim.builtin.notify.active then
  126. pcall(function()
  127. require("telescope").load_extension "notify"
  128. end)
  129. end
  130. if lvim.builtin.telescope.on_config_done then
  131. lvim.builtin.telescope.on_config_done(telescope)
  132. end
  133. if lvim.builtin.telescope.extensions and lvim.builtin.telescope.extensions.fzf then
  134. pcall(function()
  135. require("telescope").load_extension "fzf"
  136. end)
  137. end
  138. end
  139. return M