Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Implement action selection menu for :SessionManager #109

Merged
merged 4 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lua/session_manager/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ local session_manager = {}
---@param values table
function session_manager.setup(values) setmetatable(config, { __index = vim.tbl_extend('force', config.defaults, values) }) end

-- Displays action selection menu for :SessionManager
function session_manager.available_commands()
local commands = {}
for cmd, _ in pairs(session_manager) do
if cmd ~= 'setup' and cmd ~= 'available_commands' and cmd ~= 'autosave_session' then
table.insert(commands, cmd)
end
end
vim.ui.select(commands, {
prompt = 'Session Manager',
format_item = function(item) return item:sub(1, 1):upper() .. item:sub(2):gsub('_', ' ') end,
}, function(item)
if item then
session_manager[item]()
end
end)
end

--- Selects a session a loads it.
---@param discard_current boolean: If `true`, do not check for unsaved buffers.
function session_manager.load_session(discard_current)
Expand Down
4 changes: 4 additions & 0 deletions lua/session_manager/subcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ end
--- Run specified subcommand received from completion.
---@param subcommand table
function subcommands.run(subcommand)
if subcommand.args == '' then
session_manager.available_commands()
return
end
local subcommand_func = session_manager[subcommand.fargs[1]]
if not subcommand_func then
utils.notify('No such subcommand: ' .. subcommand.fargs[1], vim.log.levels.ERROR)
Expand Down
2 changes: 1 addition & 1 deletion plugin/session_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end
local subcommands = require('session_manager.subcommands')
local session_manager = require('session_manager')

vim.api.nvim_create_user_command('SessionManager', subcommands.run, { nargs = 1, bang = true, complete = subcommands.complete, desc = 'Run session manager command' })
vim.api.nvim_create_user_command('SessionManager', subcommands.run, { nargs = '*', bang = true, complete = subcommands.complete, desc = 'Run session manager command' })

local session_manager_group = vim.api.nvim_create_augroup('SessionManager', {})
vim.api.nvim_create_autocmd({ 'VimEnter' }, {
Expand Down
Loading