diff --git a/src/buffers.lua b/src/buffers.lua index 3543563..01786c1 100644 --- a/src/buffers.lua +++ b/src/buffers.lua @@ -11,6 +11,11 @@ local function create(name, content) print(" ++ created buffer '" .. name .. "' on " .. state.workspace) end +local function delete(name) + state.client:get_workspace(state.workspace):delete_buffer(name) + print(" -- deleted buffer " .. name) +end + local function attach(name, force) local buffer = nil if force then @@ -23,7 +28,7 @@ local function attach(name, force) vim.api.nvim_buf_set_name(buffer, "codemp::" .. name) vim.api.nvim_set_current_buf(buffer) end - local controller = state.client:get_workspace(state.workspace):attach_buffer(name) + local controller = state.client:get_workspace(state.workspace):attach(name) -- TODO map name to uuid @@ -70,7 +75,7 @@ local function detach(name) local buffer = buffer_id_map[name] id_buffer_map[buffer] = nil buffer_id_map[name] = nil - state.client:get_workspace(state.workspace):disconnect_buffer(name) + state.client:get_workspace(state.workspace):detach(name) vim.api.nvim_buf_delete(buffer, {}) print(" -- detached from buffer " .. name) @@ -92,6 +97,7 @@ end return { create = create, + delete = delete, sync = sync, attach = attach, detach = detach, diff --git a/src/command.lua b/src/command.lua index 4ef736e..e5825ce 100644 --- a/src/command.lua +++ b/src/command.lua @@ -37,6 +37,12 @@ local connected_actions = { workspace.join(ws) print(" >< joined workspace " .. ws) end, + + disconnect = function() + print(" xx disconnecting client " .. state.client.id) + native.close_client(state.client.id) + state.client = nil + end, } -- only available if state.workspace is not nil @@ -46,6 +52,11 @@ local joined_actions = { buffers.create(path) end, + delete = function(path) + if path == nil then error("missing buffer name") end + buffers.delete(path) + end, + buffers = function() workspace.open_buffer_tree() end, @@ -59,6 +70,15 @@ local joined_actions = { buffers.attach(path, bang) end, + detach = function(path) + if path == nil then error("missing buffer name") end + buffers.detach(path) + end, + + leave = function(ws) + if ws == nil then error("missing workspace to leave") end + state.client:leave_workspace(ws) + end, } vim.api.nvim_create_user_command(