From 07344401dc35dcd373580eb36fcf163a19916b7a Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 15 Sep 2024 12:39:12 +0200 Subject: [PATCH] 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 --- lua/codemp/command.lua | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lua/codemp/command.lua b/lua/codemp/command.lua index 66bd0a7..c7dbb7d 100644 --- a/lua/codemp/command.lua +++ b/lua/codemp/command.lua @@ -32,8 +32,15 @@ local connected_actions = { end, join = function(ws) - if ws == nil then error("missing workspace name") end - workspace.join(ws) + 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,15 +115,25 @@ local joined_actions = { end, attach = function(path, bang) - if path == nil then error("missing buffer name") end - local buffer = nil - if bang then - buffer = vim.api.nvim_get_current_buf() - else - buffer = vim.api.nvim_create_buf(true, false) - vim.api.nvim_set_current_buf(buffer) + local function doit(p) + local buffer = nil + if bang then + buffer = vim.api.nvim_get_current_buf() + else + buffer = vim.api.nvim_create_buf(true, false) + 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 - buffers.attach(path, buffer) end, detach = function(path)