telescope.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. git_files = {
  80. show_untracked = true,
  81. },
  82. },
  83. extensions = {
  84. fzf = {
  85. fuzzy = true, -- false will only do exact matching
  86. override_generic_sorter = true, -- override the generic sorter
  87. override_file_sorter = true, -- override the file sorter
  88. case_mode = "smart_case", -- or "ignore_case" or "respect_case"
  89. },
  90. },
  91. })
  92. end
  93. function M.setup()
  94. local previewers = require "telescope.previewers"
  95. local sorters = require "telescope.sorters"
  96. local actions = require "telescope.actions"
  97. lvim.builtin.telescope = vim.tbl_extend("keep", {
  98. file_previewer = previewers.vim_buffer_cat.new,
  99. grep_previewer = previewers.vim_buffer_vimgrep.new,
  100. qflist_previewer = previewers.vim_buffer_qflist.new,
  101. file_sorter = sorters.get_fuzzy_file,
  102. generic_sorter = sorters.get_generic_fuzzy_sorter,
  103. ---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults.
  104. mappings = {
  105. i = {
  106. ["<C-n>"] = actions.move_selection_next,
  107. ["<C-p>"] = actions.move_selection_previous,
  108. ["<C-c>"] = actions.close,
  109. ["<C-j>"] = actions.cycle_history_next,
  110. ["<C-k>"] = actions.cycle_history_prev,
  111. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  112. ["<CR>"] = actions.select_default + actions.center,
  113. },
  114. n = {
  115. ["<C-n>"] = actions.move_selection_next,
  116. ["<C-p>"] = actions.move_selection_previous,
  117. ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
  118. },
  119. },
  120. }, lvim.builtin.telescope)
  121. local telescope = require "telescope"
  122. telescope.setup(lvim.builtin.telescope)
  123. if lvim.builtin.project.active then
  124. pcall(function()
  125. require("telescope").load_extension "projects"
  126. end)
  127. end
  128. if lvim.builtin.notify.active then
  129. pcall(function()
  130. require("telescope").load_extension "notify"
  131. end)
  132. end
  133. if lvim.builtin.telescope.on_config_done then
  134. lvim.builtin.telescope.on_config_done(telescope)
  135. end
  136. if lvim.builtin.telescope.extensions and lvim.builtin.telescope.extensions.fzf then
  137. pcall(function()
  138. require("telescope").load_extension "fzf"
  139. end)
  140. end
  141. end
  142. return M