mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 10:15: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
|
elseif layer.isLoaded('leaderf') then
|
||||||
sp.cmd("call SpaceVim#layers#leaderf#run_menu('Projects')")
|
sp.cmd("call SpaceVim#layers#leaderf#run_menu('Projects')")
|
||||||
elseif layer.isLoaded('telescope') then
|
elseif layer.isLoaded('telescope') then
|
||||||
sp.cmd('Telescope menu menu=Projects')
|
sp.cmd('Telescope project')
|
||||||
else
|
else
|
||||||
logger.warn('fuzzy find layer is needed to find project!')
|
logger.warn('fuzzy find layer is needed to find project!')
|
||||||
end
|
end
|
||||||
@ -305,7 +305,7 @@ end
|
|||||||
|
|
||||||
function M.open(project)
|
function M.open(project)
|
||||||
local path = project_paths[project]['path']
|
local path = project_paths[project]['path']
|
||||||
local name = project_paths[project]['name']
|
-- local name = project_paths[project]['name']
|
||||||
sp.cmd('tabnew')
|
sp.cmd('tabnew')
|
||||||
-- I am not sure we should set the project name here.
|
-- I am not sure we should set the project name here.
|
||||||
-- sp.cmd('let t:_spacevim_tab_name = "[' .. name .. ']"')
|
-- sp.cmd('let t:_spacevim_tab_name = "[' .. name .. ']"')
|
||||||
@ -449,4 +449,9 @@ function M.current_root()
|
|||||||
return rootdir
|
return rootdir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_project_history() -- {{{
|
||||||
|
return project_paths
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -1,71 +1,75 @@
|
|||||||
local action_state = require("telescope.actions.state")
|
local action_state = require('telescope.actions.state')
|
||||||
local actions = require("telescope.actions")
|
local actions = require('telescope.actions')
|
||||||
local conf = require("telescope.config").values
|
local conf = require('telescope.config').values
|
||||||
local entry_display = require("telescope.pickers.entry_display")
|
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 pm = require('spacevim.plugin.projectmanager')
|
||||||
|
|
||||||
local function get_all_projects()
|
local function get_all_projects()
|
||||||
local p = {}
|
local p = {}
|
||||||
local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates')
|
local projects = pm.get_project_history()
|
||||||
|
|
||||||
for _, project in pairs(projects) do
|
for _, k in pairs(projects) do
|
||||||
table.insert(p, project)
|
table.insert(p, k)
|
||||||
end
|
end
|
||||||
return p
|
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 = 20 },
|
{ width = 20 },
|
||||||
{ width = vim.api.nvim_win_get_width(0) - 60 },
|
{ width = vim.api.nvim_win_get_width(0) - 60 },
|
||||||
{ remaining = true },
|
{ 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)
|
end
|
||||||
-- print(vim.inspect(entry))
|
pickers
|
||||||
return displayer({
|
.new(opts, {
|
||||||
{ '[' .. entry.value.name .. ']', 'TelescopeResultsVariable' },
|
prompt_title = 'Projects',
|
||||||
{ entry.value.path, 'TelescopeResultsFunction' },
|
finder = finders.new_table({
|
||||||
{ '<' .. vim.fn.strftime('%Y-%m-%d %T', entry.value.opened_time) .. '>', 'TelescopeResultsComment' },
|
results = get_all_projects(),
|
||||||
})
|
entry_maker = function(entry)
|
||||||
end
|
return {
|
||||||
pickers.new(opts, {
|
value = entry,
|
||||||
prompt_title = "Projects",
|
display = make_display,
|
||||||
finder = finders.new_table {
|
ordinal = entry.name,
|
||||||
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,
|
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
|
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,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user