telescope.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. local M = {}
  2. ---@alias telescope_themes
  3. ---| "cursor" # see `telescope.themes.get_cursor()`
  4. ---| "dropdown" # see `telescope.themes.get_dropdown()`
  5. ---| "ivy" # see `telescope.themes.get_ivy()`
  6. ---| "center" # retain the default telescope theme
  7. function M.config()
  8. local actions = require("lvim.utils.modules").require_on_exported_call "telescope.actions"
  9. lvim.builtin.telescope = {
  10. ---@usage disable telescope completely [not recommended]
  11. active = true,
  12. on_config_done = nil,
  13. theme = "dropdown", ---@type telescope_themes
  14. defaults = {
  15. prompt_prefix = lvim.icons.ui.Telescope .. " ",
  16. selection_caret = lvim.icons.ui.Forward .. " ",
  17. entry_prefix = " ",
  18. initial_mode = "insert",
  19. selection_strategy = "reset",
  20. sorting_strategy = nil,
  21. layout_strategy = nil,
  22. layout_config = {},
  23. vimgrep_arguments = {
  24. "rg",
  25. "--color=never",
  26. "--no-heading",
  27. "--with-filename",
  28. "--line-number",
  29. "--column",
  30. "--smart-case",
  31. "--hidden",
  32. "--glob=!.git/",
  33. },
  34. ---@usage Mappings are fully customizable. Many familiar mapping patterns are setup as defaults.
  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>"] = function(...)
  43. actions.smart_send_to_qflist(...)
  44. actions.open_qflist(...)
  45. end,
  46. ["<CR>"] = actions.select_default,
  47. },
  48. n = {
  49. ["<C-n>"] = actions.move_selection_next,
  50. ["<C-p>"] = actions.move_selection_previous,
  51. ["<C-q>"] = function(...)
  52. actions.smart_send_to_qflist(...)
  53. actions.open_qflist(...)
  54. end,
  55. },
  56. },
  57. file_ignore_patterns = {},
  58. path_display = { "smart" },
  59. winblend = 0,
  60. border = {},
  61. borderchars = nil,
  62. color_devicons = true,
  63. set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil,
  64. },
  65. pickers = {
  66. find_files = {
  67. hidden = true,
  68. },
  69. live_grep = {
  70. --@usage don't include the filename in the search results
  71. only_sort_text = true,
  72. },
  73. grep_string = {
  74. only_sort_text = true,
  75. },
  76. buffers = {
  77. initial_mode = "normal",
  78. mappings = {
  79. i = {
  80. ["<C-d>"] = actions.delete_buffer,
  81. },
  82. n = {
  83. ["dd"] = actions.delete_buffer,
  84. },
  85. },
  86. },
  87. planets = {
  88. show_pluto = true,
  89. show_moon = true,
  90. },
  91. git_files = {
  92. hidden = true,
  93. show_untracked = true,
  94. },
  95. colorscheme = {
  96. enable_preview = true,
  97. },
  98. },
  99. extensions = {
  100. fzf = {
  101. fuzzy = true, -- false will only do exact matching
  102. override_generic_sorter = true, -- override the generic sorter
  103. override_file_sorter = true, -- override the file sorter
  104. case_mode = "smart_case", -- or "ignore_case" or "respect_case"
  105. },
  106. },
  107. }
  108. end
  109. function M.setup()
  110. local previewers = require "telescope.previewers"
  111. local sorters = require "telescope.sorters"
  112. lvim.builtin.telescope = vim.tbl_extend("keep", {
  113. file_previewer = previewers.vim_buffer_cat.new,
  114. grep_previewer = previewers.vim_buffer_vimgrep.new,
  115. qflist_previewer = previewers.vim_buffer_qflist.new,
  116. file_sorter = sorters.get_fuzzy_file,
  117. generic_sorter = sorters.get_generic_fuzzy_sorter,
  118. }, lvim.builtin.telescope)
  119. local telescope = require "telescope"
  120. local theme = require("telescope.themes")["get_" .. (lvim.builtin.telescope.theme or "")]
  121. if theme then
  122. lvim.builtin.telescope.defaults = theme(lvim.builtin.telescope.defaults)
  123. end
  124. telescope.setup(lvim.builtin.telescope)
  125. if lvim.builtin.project.active then
  126. pcall(function()
  127. require("telescope").load_extension "projects"
  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