mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-12 17:55:41 +08:00
feat(project): improve Telescope project
This commit is contained in:
parent
472e982bb1
commit
eda0c97f4a
@ -297,7 +297,7 @@ function M.list()
|
||||
elseif layer.isLoaded('leaderf') then
|
||||
sp.cmd("call SpaceVim#layers#leaderf#run_menu('Projects')")
|
||||
elseif layer.isLoaded('telescope') then
|
||||
sp.cmd('Telescope menu menu=Projects')
|
||||
sp.cmd('Telescope project')
|
||||
else
|
||||
logger.warn('fuzzy find layer is needed to find project!')
|
||||
end
|
||||
@ -305,7 +305,7 @@ end
|
||||
|
||||
function M.open(project)
|
||||
local path = project_paths[project]['path']
|
||||
local name = project_paths[project]['name']
|
||||
-- local name = project_paths[project]['name']
|
||||
sp.cmd('tabnew')
|
||||
-- I am not sure we should set the project name here.
|
||||
-- sp.cmd('let t:_spacevim_tab_name = "[' .. name .. ']"')
|
||||
@ -449,4 +449,9 @@ function M.current_root()
|
||||
return rootdir
|
||||
end
|
||||
|
||||
function M.get_project_history() -- {{{
|
||||
return project_paths
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return M
|
||||
|
@ -1,71 +1,75 @@
|
||||
local action_state = require("telescope.actions.state")
|
||||
local actions = require("telescope.actions")
|
||||
local conf = require("telescope.config").values
|
||||
local entry_display = require("telescope.pickers.entry_display")
|
||||
local finders = require("telescope.finders")
|
||||
local pickers = require("telescope.pickers")
|
||||
local action_state = require('telescope.actions.state')
|
||||
local actions = require('telescope.actions')
|
||||
local conf = require('telescope.config').values
|
||||
local entry_display = require('telescope.pickers.entry_display')
|
||||
local finders = require('telescope.finders')
|
||||
local pickers = require('telescope.pickers')
|
||||
local pm = require('spacevim.plugin.projectmanager')
|
||||
|
||||
local function get_all_projects()
|
||||
local p = {}
|
||||
local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates')
|
||||
local p = {}
|
||||
local projects = pm.get_project_history()
|
||||
|
||||
for _, project in pairs(projects) do
|
||||
table.insert(p, project)
|
||||
end
|
||||
return p
|
||||
for _, k in pairs(projects) do
|
||||
table.insert(p, k)
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local function show_changes(opts)
|
||||
opts = opts or {}
|
||||
local displayer = entry_display.create({
|
||||
separator = ' ',
|
||||
items = {
|
||||
{ width = 20 },
|
||||
{ width = vim.api.nvim_win_get_width(0) - 60 },
|
||||
{ remaining = true },
|
||||
},
|
||||
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',
|
||||
},
|
||||
})
|
||||
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
|
||||
pickers
|
||||
.new(opts, {
|
||||
prompt_title = 'Projects',
|
||||
finder = finders.new_table({
|
||||
results = get_all_projects(),
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry,
|
||||
display = make_display,
|
||||
ordinal = entry.name,
|
||||
}
|
||||
end,
|
||||
}):find()
|
||||
}),
|
||||
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)
|
||||
pm.open(entry.value.path)
|
||||
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,
|
||||
},
|
||||
return require('telescope').register_extension({
|
||||
exports = {
|
||||
-- Default when to argument is given, i.e. :Telescope project
|
||||
project = run,
|
||||
},
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user