From ef41a3d24e753b7e82fe31ebe9e74048881c13e8 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 15 Oct 2021 16:33:34 +0200 Subject: feat: better telescope integration (#1702) --- lua/lvim/core/telescope/custom-finders.lua | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lua/lvim/core/telescope/custom-finders.lua (limited to 'lua/lvim/core/telescope') diff --git a/lua/lvim/core/telescope/custom-finders.lua b/lua/lvim/core/telescope/custom-finders.lua new file mode 100644 index 00000000..c3347fd0 --- /dev/null +++ b/lua/lvim/core/telescope/custom-finders.lua @@ -0,0 +1,80 @@ +local M = {} + +local _, builtin = pcall(require, "telescope.builtin") +local _, finders = pcall(require, "telescope.finders") +local _, pickers = pcall(require, "telescope.pickers") +local _, sorters = pcall(require, "telescope.sorters") +local _, themes = pcall(require, "telescope.themes") +local _, actions = pcall(require, "telescope.actions") +local _, previewers = pcall(require, "telescope.previewers") +local _, make_entry = pcall(require, "telescope.make_entry") + +local utils = require "lvim.utils" + +function M.find_lunarvim_files(opts) + opts = opts or {} + local theme_opts = themes.get_ivy { + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + prompt_prefix = ">> ", + prompt_title = "~ LunarVim files ~", + cwd = get_runtime_dir(), + search_dirs = { utils.join_paths(get_runtime_dir(), "lvim"), lvim.lsp.templates_dir }, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + builtin.find_files(opts) +end + +function M.grep_lunarvim_files(opts) + opts = opts or {} + local theme_opts = themes.get_ivy { + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + prompt_prefix = ">> ", + prompt_title = "~ search LunarVim ~", + cwd = get_runtime_dir(), + search_dirs = { utils.join_paths(get_runtime_dir(), "lvim"), lvim.lsp.templates_dir }, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + builtin.live_grep(opts) +end + +function M.view_lunarvim_changelog() + local opts = {} + opts.entry_maker = make_entry.gen_from_git_commits(opts) + + pickers.new(opts, { + prompt_title = "LunarVim changelog", + + finder = finders.new_oneshot_job( + vim.tbl_flatten { + "git", + "log", + "--pretty=oneline", + "--abbrev-commit", + "--", + ".", + }, + opts + ), + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + + --TODO: consider opening a diff view when pressing enter + attach_mappings = function(_, map) + map("i", "", actions._close) + map("n", "", actions._close) + map("i", "", actions._close) + map("n", "", actions._close) + map("n", "q", actions._close) + return true + end, + sorter = sorters.generic_sorter, + }):find() +end + +return M -- cgit v1.2.3