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, end,
join = function(ws) join = function(ws)
if ws == nil then error("missing workspace name") end if ws == nil then
workspace.join(ws) 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, end,
start = function(ws) start = function(ws)
@ -108,15 +115,25 @@ local joined_actions = {
end, end,
attach = function(path, bang) attach = function(path, bang)
if path == nil then error("missing buffer name") end local function doit(p)
local buffer = nil local buffer = nil
if bang then if bang then
buffer = vim.api.nvim_get_current_buf() buffer = vim.api.nvim_get_current_buf()
else else
buffer = vim.api.nvim_create_buf(true, false) buffer = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buffer) vim.api.nvim_set_current_buf(buffer)
end
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
buffers.attach(path, buffer)
end, end,
detach = function(path) detach = function(path)