feat: workspace join and buffer attach show picker

when invoked as command without argument, rather than failing will show
a vim.ui.select with all available options
This commit is contained in:
əlemi 2024-09-15 12:39:12 +02:00
parent a0c1fb3acd
commit 07344401dc
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -32,8 +32,15 @@ local connected_actions = {
end,
join = function(ws)
if ws == nil then error("missing workspace name") end
if ws == nil then
local opts = { prompt = "Select workspace to join:", format_item = function (x) return x.name end }
return vim.ui.select(session.available, opts, function (choice)
if choice == nil then return end -- action canceled by user
workspace.join(session.available[choice].name)
end)
else
workspace.join(ws)
end
end,
start = function(ws)
@ -108,7 +115,7 @@ local joined_actions = {
end,
attach = function(path, bang)
if path == nil then error("missing buffer name") end
local function doit(p)
local buffer = nil
if bang then
buffer = vim.api.nvim_get_current_buf()
@ -116,7 +123,17 @@ local joined_actions = {
buffer = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buffer)
end
buffers.attach(path, buffer)
buffers.attach(p, buffer)
end
if path == nil then
local filetree = session.workspace:filetree(nil, false)
return vim.ui.select(filetree, { prompt = "Select buffer to attach to:" }, function (choice)
if choice == nil then return end -- action canceled by user
doit(filetree[choice])
end)
else
doit(path)
end
end,
detach = function(path)