From a9430e56a302a66d57fa3f7af80a74e6d037bd2c Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Sun, 13 Feb 2022 17:53:07 +0100 Subject: more refactor --- lua/alpha/plugins.lua | 2 +- lua/alpha/telescope/init.lua | 64 ++++++++++++++++++++++++++++- lua/alpha/telescope/mappings.lua | 5 +-- lua/alpha/telescope_laravel.lua | 89 ---------------------------------------- 4 files changed, 66 insertions(+), 94 deletions(-) delete mode 100644 lua/alpha/telescope_laravel.lua (limited to 'lua') diff --git a/lua/alpha/plugins.lua b/lua/alpha/plugins.lua index 5591695..4b59016 100644 --- a/lua/alpha/plugins.lua +++ b/lua/alpha/plugins.lua @@ -122,7 +122,7 @@ return require('packer').startup(function(use) use 'vim-test/vim-test' - use 'fatih/vim-go' + -- use 'fatih/vim-go' use { 'noahfrederick/vim-laravel', diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua index 7b0ffd2..da99b32 100644 --- a/lua/alpha/telescope/init.lua +++ b/lua/alpha/telescope/init.lua @@ -1,3 +1,15 @@ +SHOULD_RELOAD_TELESCOPE = true + +local reloader = function() + if SHOULD_RELOAD_TELESCOPE then + RELOAD "plenary" + RELOAD "telescope" + RELOAD "alpha.telescope.setup" + end +end + +local action_state = require "telescope.actions.state" +local fb_actions = require "telescope".extensions.file_browser.actions local actions = require('telescope.actions') local M = {} @@ -51,9 +63,59 @@ function M.my_plugins() } end +function M.projectionist () + return require("telescope").extensions.projectionist.projectionist() +end + +function M.laravel () + return require("telescope").extensions.laravel.laravel() +end + +function M.file_browser () + local opts + + opts = { + sorting_strategy = "ascending", + scroll_strategy = "cycle", + layout_config = { + prompt_position = "top", + }, + + attach_mappings = function(prompt_bufnr, map) + local current_picker = action_state.get_current_picker(prompt_bufnr) + + local modify_cwd = function(new_cwd) + local finder = current_picker.finder + + finder.path = new_cwd + finder.files = true + current_picker:refresh(false, { reset_prompt = true }) + end + + map("i", "-", function() + modify_cwd(current_picker.cwd .. "/..") + end) + + map("i", "~", function() + modify_cwd(vim.fn.expand "~") + end) + + map("n", "yy", function() + local entry = action_state.get_selected_entry() + vim.fn.setreg("+", entry.value) + end) + + map("i", "", fb_actions.create) + + return true + end, + } + return require("telescope").extensions.file_browser.file_browser(opts) +end + return setmetatable({}, { __index = function(_, k) - + reloader() if M[k] then return M[k] else diff --git a/lua/alpha/telescope/mappings.lua b/lua/alpha/telescope/mappings.lua index 411fc0c..8ffc15a 100644 --- a/lua/alpha/telescope/mappings.lua +++ b/lua/alpha/telescope/mappings.lua @@ -34,13 +34,12 @@ map_tele("ph", "help_tags") map_tele("pe", "buffers") map_tele("pr", "treesitter") map_tele("bb", "file_browser") -map_tele("vrr", "lsp_references") map_tele("gs", "git_status") -map_tele("pv", "find_symbol") -map_tele("ve", "lsp_document_diagnostics") +map_tele("ve", "diagnostics") map_tele("fp", "my_plugins") map_tele("pa", "laravel") +map_tele("vca", "lsp_code_actions") diff --git a/lua/alpha/telescope_laravel.lua b/lua/alpha/telescope_laravel.lua deleted file mode 100644 index fc730b6..0000000 --- a/lua/alpha/telescope_laravel.lua +++ /dev/null @@ -1,89 +0,0 @@ -local actions = require('telescope.actions') -local pickers = require "telescope.pickers" -local finders = require "telescope.finders" -local previewers = require "telescope.previewers" -local conf = require("telescope.config").values -local putils = require "telescope.previewers.utils" -local action_state = require "telescope.actions.state" -local utils = require "telescope.utils" -local laravel = {} - -function Split(s, delimiter) - local result = {}; - for match in (s..delimiter):gmatch("(.-)"..delimiter) do - table.insert(result, match); - end - return result; -end - -local lookup_keys = { - display = 1, - ordinal = 1, - value = 1, -} - -local mt_string_entry = { - __index = function(t, k) - return rawget(t, rawget(lookup_keys, k)) - end, -} - -local function getArtisanCommand(args) - local artCmdStr = vim.g.laravel_artisan - if artCmdStr == nil then - artCmdStr = "php artisan" - end - if type(args) ~= "table" then - return Split(artCmdStr .. ' ' .. args, " ") - end - local cmd = Split(artCmdStr, ' ') - for _, value in ipairs(args) do - table.insert(cmd, value) - end - - return cmd -end - -laravel.artisan = function() - - local results = utils.get_os_command_output(getArtisanCommand('--raw')) - - pickers.new({}, { - prompt_title = "Artisan commands", - finder = finders.new_table { - results = results, - entry_maker = function (line) - return setmetatable({ - Split(line, " ")[1], - }, mt_string_entry) - end - }, - previewer = previewers.new_buffer_previewer { - title = "Help", - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - - local cmd = getArtisanCommand({entry.value, '-h'}) - - putils.job_maker(cmd, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - }) - end, - }, - sorter = conf.file_sorter(), - attach_mappings = function (_, map) - map('i', '', function(prompt_bufnr) - local entry = action_state.get_selected_entry() - actions.close(prompt_bufnr) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(":Artisan " .. entry.value .. " ", true, false, true), "t", true) - end) - return true - end - }):find() -end - -return laravel -- cgit v1.2.3