From d69df0a1524bbd13814755b7be7286cc9860aadd Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 19 May 2022 11:07:16 +0800 Subject: [PATCH] feat(projectmanager): improve Telescope project extension --- autoload/SpaceVim/plugins/projectmanager.vim | 2 +- docs/_posts/2018-09-28-use-vim-as-ide.md | 5 + lua/telescope/_extensions/project.lua | 106 +++++++++---------- 3 files changed, 58 insertions(+), 55 deletions(-) diff --git a/autoload/SpaceVim/plugins/projectmanager.vim b/autoload/SpaceVim/plugins/projectmanager.vim index d60803d3e..b8c13988d 100644 --- a/autoload/SpaceVim/plugins/projectmanager.vim +++ b/autoload/SpaceVim/plugins/projectmanager.vim @@ -129,7 +129,7 @@ else for key in s:sort_by_opened_time() let desc = '[' . s:project_paths[key].name . '] ' . s:project_paths[key].path . ' <' . strftime('%Y-%m-%d %T', s:project_paths[key].opened_time) . '>' let cmd = "call SpaceVim#plugins#projectmanager#open('" . s:project_paths[key].path . "')" - call add(g:unite_source_menu_menus.Projects.command_candidates, [desc,cmd]) + call add(g:unite_source_menu_menus.Projects.command_candidates, [desc, cmd, s:project_paths[key]]) endfor if g:spacevim_enable_projects_cache call s:cache() diff --git a/docs/_posts/2018-09-28-use-vim-as-ide.md b/docs/_posts/2018-09-28-use-vim-as-ide.md index 6bcd34754..c374621a3 100644 --- a/docs/_posts/2018-09-28-use-vim-as-ide.md +++ b/docs/_posts/2018-09-28-use-vim-as-ide.md @@ -70,6 +70,11 @@ you need to change `project_rooter_outermost` to `false`. project_rooter_outermost = false ``` +If you want to list all recent opened project, you need to load a fuzzy finder layer. +for example `telescope` layer, the the key binding `SPC p p` is available for you. + +![image](https://user-images.githubusercontent.com/13142418/169195419-329a1b58-850d-40a8-ba02-d0e1f9367305.png) + ### Fuzzy finder SpaceVim provides 5 fuzzy finder layer, they are unite, denite, fzf, leaderf and ctrlp. diff --git a/lua/telescope/_extensions/project.lua b/lua/telescope/_extensions/project.lua index 3e6bb5de5..50d19b795 100644 --- a/lua/telescope/_extensions/project.lua +++ b/lua/telescope/_extensions/project.lua @@ -5,69 +5,67 @@ local entry_display = require("telescope.pickers.entry_display") local finders = require("telescope.finders") local pickers = require("telescope.pickers") -local function prepare_output_table() - local lines = {} - local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates') +local function get_all_projects() + local p = {} + local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates') - for _, project in pairs(projects) do - table.insert(lines, project) - end - return lines + for _, project in pairs(projects) do + table.insert(p, project) + end + return p end local function show_changes(opts) - opts = opts or {} --- local displayer = entry_display.create({ --- separator = ' ', --- items = { --- { width = 4 }, --- { remaining = true }, --- { remaining = true }, --- }, --- }) --- local function make_display(entry) --- return displayer({ --- { entry.value.type, 'TelescopeResultsVariable' }, --- { entry.value.name, 'TelescopeResultsFunction' }, --- { '[' .. entry.value.line .. ']', 'TelescopeResultsComment' }, --- }) --- end --- local function make_display(v) --- --- end - pickers.new(opts, { - prompt_title = "Projects", - finder = finders.new_table { - results = prepare_output_table(), - entry_maker = function(entry) - return { - value = entry, - command = entry[2], - display = entry[1], - ordinal = entry[1] - } - end - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr) - actions.select_default:replace(function() - local entry = action_state.get_selected_entry() - actions.close(prompt_bufnr) - vim.cmd(entry.command) - end) - return true - end, - }):find() + opts = opts or {} + local displayer = entry_display.create({ + separator = ' ', + items = { + { width = 20 }, + { width = vim.api.nvim_win_get_width(0) - 60 }, + { remaining = true }, + }, + }) + local function make_display(entry) + -- print(vim.inspect(entry)) + return displayer({ + { '[' .. entry.value.name .. ']', 'TelescopeResultsVariable' }, + { entry.value.path, 'TelescopeResultsFunction' }, + { '<' .. vim.fn.strftime('%Y-%m-%d %T', entry.value.opened_time) .. '>', 'TelescopeResultsComment' }, + }) + end + pickers.new(opts, { + prompt_title = "Projects", + finder = finders.new_table { + results = get_all_projects(), + entry_maker = function(entry) + return { + value = entry[3], + command = entry[2], + display = make_display, + ordinal = entry[1] + } + end + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr) + actions.select_default:replace(function() + local entry = action_state.get_selected_entry() + actions.close(prompt_bufnr) + vim.cmd(entry.command) + end) + return true + end, + }):find() end local function run() - show_changes() + show_changes() end return require("telescope").register_extension({ - exports = { - -- Default when to argument is given, i.e. :Telescope project - project = run, - }, + exports = { + -- Default when to argument is given, i.e. :Telescope project + project = run, + }, })