1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:40:05 +08:00

feat(projectmanager): improve Telescope project extension

This commit is contained in:
wsdjeg 2022-05-19 11:07:16 +08:00
parent 3c8514f611
commit d69df0a152
3 changed files with 58 additions and 55 deletions

View File

@ -129,7 +129,7 @@ else
for key in s:sort_by_opened_time() 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 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 . "')" 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 endfor
if g:spacevim_enable_projects_cache if g:spacevim_enable_projects_cache
call s:cache() call s:cache()

View File

@ -70,6 +70,11 @@ you need to change `project_rooter_outermost` to `false`.
project_rooter_outermost = 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 ### Fuzzy finder
SpaceVim provides 5 fuzzy finder layer, they are unite, denite, fzf, leaderf and ctrlp. SpaceVim provides 5 fuzzy finder layer, they are unite, denite, fzf, leaderf and ctrlp.

View File

@ -5,69 +5,67 @@ local entry_display = require("telescope.pickers.entry_display")
local finders = require("telescope.finders") local finders = require("telescope.finders")
local pickers = require("telescope.pickers") local pickers = require("telescope.pickers")
local function prepare_output_table() local function get_all_projects()
local lines = {} local p = {}
local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates') local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates')
for _, project in pairs(projects) do for _, project in pairs(projects) do
table.insert(lines, project) table.insert(p, project)
end end
return lines return p
end end
local function show_changes(opts) local function show_changes(opts)
opts = opts or {} opts = opts or {}
-- local displayer = entry_display.create({ local displayer = entry_display.create({
-- separator = ' ', separator = ' ',
-- items = { items = {
-- { width = 4 }, { width = 20 },
-- { remaining = true }, { width = vim.api.nvim_win_get_width(0) - 60 },
-- { remaining = true }, { remaining = true },
-- }, },
-- }) })
-- local function make_display(entry) local function make_display(entry)
-- return displayer({ -- print(vim.inspect(entry))
-- { entry.value.type, 'TelescopeResultsVariable' }, return displayer({
-- { entry.value.name, 'TelescopeResultsFunction' }, { '[' .. entry.value.name .. ']', 'TelescopeResultsVariable' },
-- { '[' .. entry.value.line .. ']', 'TelescopeResultsComment' }, { entry.value.path, 'TelescopeResultsFunction' },
-- }) { '<' .. vim.fn.strftime('%Y-%m-%d %T', entry.value.opened_time) .. '>', 'TelescopeResultsComment' },
-- end })
-- local function make_display(v) end
-- pickers.new(opts, {
-- end prompt_title = "Projects",
pickers.new(opts, { finder = finders.new_table {
prompt_title = "Projects", results = get_all_projects(),
finder = finders.new_table { entry_maker = function(entry)
results = prepare_output_table(), return {
entry_maker = function(entry) value = entry[3],
return { command = entry[2],
value = entry, display = make_display,
command = entry[2], ordinal = entry[1]
display = entry[1], }
ordinal = entry[1] end
} },
end sorter = conf.generic_sorter(opts),
}, attach_mappings = function(prompt_bufnr)
sorter = conf.generic_sorter(opts), actions.select_default:replace(function()
attach_mappings = function(prompt_bufnr) local entry = action_state.get_selected_entry()
actions.select_default:replace(function() actions.close(prompt_bufnr)
local entry = action_state.get_selected_entry() vim.cmd(entry.command)
actions.close(prompt_bufnr) end)
vim.cmd(entry.command) return true
end) end,
return true }):find()
end,
}):find()
end end
local function run() local function run()
show_changes() show_changes()
end end
return require("telescope").register_extension({ return require("telescope").register_extension({
exports = { exports = {
-- Default when to argument is given, i.e. :Telescope project -- Default when to argument is given, i.e. :Telescope project
project = run, project = run,
}, },
}) })