custom-finders.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local M = {}
  2. local _, builtin = pcall(require, "telescope.builtin")
  3. local _, finders = pcall(require, "telescope.finders")
  4. local _, pickers = pcall(require, "telescope.pickers")
  5. local _, sorters = pcall(require, "telescope.sorters")
  6. local _, themes = pcall(require, "telescope.themes")
  7. local _, actions = pcall(require, "telescope.actions")
  8. local _, previewers = pcall(require, "telescope.previewers")
  9. local _, make_entry = pcall(require, "telescope.make_entry")
  10. local utils = require "lvim.utils"
  11. function M.find_lunarvim_files(opts)
  12. opts = opts or {}
  13. local theme_opts = themes.get_ivy {
  14. sorting_strategy = "ascending",
  15. layout_strategy = "bottom_pane",
  16. prompt_prefix = ">> ",
  17. prompt_title = "~ LunarVim files ~",
  18. cwd = get_runtime_dir(),
  19. search_dirs = { utils.join_paths(get_runtime_dir(), "lvim"), lvim.lsp.templates_dir },
  20. }
  21. opts = vim.tbl_deep_extend("force", theme_opts, opts)
  22. builtin.find_files(opts)
  23. end
  24. function M.grep_lunarvim_files(opts)
  25. opts = opts or {}
  26. local theme_opts = themes.get_ivy {
  27. sorting_strategy = "ascending",
  28. layout_strategy = "bottom_pane",
  29. prompt_prefix = ">> ",
  30. prompt_title = "~ search LunarVim ~",
  31. cwd = get_runtime_dir(),
  32. search_dirs = { utils.join_paths(get_runtime_dir(), "lvim"), lvim.lsp.templates_dir },
  33. }
  34. opts = vim.tbl_deep_extend("force", theme_opts, opts)
  35. builtin.live_grep(opts)
  36. end
  37. function M.view_lunarvim_changelog()
  38. local opts = { cwd = get_lvim_base_dir() }
  39. opts.entry_maker = make_entry.gen_from_git_commits(opts)
  40. pickers.new(opts, {
  41. prompt_title = "LunarVim changelog",
  42. finder = finders.new_oneshot_job(
  43. vim.tbl_flatten {
  44. "git",
  45. "log",
  46. "--pretty=oneline",
  47. "--abbrev-commit",
  48. },
  49. opts
  50. ),
  51. previewer = {
  52. previewers.git_commit_diff_to_parent.new(opts),
  53. previewers.git_commit_diff_to_head.new(opts),
  54. previewers.git_commit_diff_as_was.new(opts),
  55. previewers.git_commit_message.new(opts),
  56. },
  57. --TODO: consider opening a diff view when pressing enter
  58. attach_mappings = function(_, map)
  59. map("i", "<enter>", actions._close)
  60. map("n", "<enter>", actions._close)
  61. map("i", "<esc>", actions._close)
  62. map("n", "<esc>", actions._close)
  63. map("n", "q", actions._close)
  64. return true
  65. end,
  66. sorter = sorters.generic_sorter,
  67. }):find()
  68. end
  69. return M