1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:50: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()
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()

View File

@ -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.

View File

@ -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,
},
})