mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
feat: commands to leave, delete, detach
This commit is contained in:
parent
44d9f9766b
commit
72661a2eec
2 changed files with 28 additions and 2 deletions
|
@ -11,6 +11,11 @@ local function create(name, content)
|
||||||
print(" ++ created buffer '" .. name .. "' on " .. state.workspace)
|
print(" ++ created buffer '" .. name .. "' on " .. state.workspace)
|
||||||
end
|
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 function attach(name, force)
|
||||||
local buffer = nil
|
local buffer = nil
|
||||||
if force then
|
if force then
|
||||||
|
@ -23,7 +28,7 @@ local function attach(name, force)
|
||||||
vim.api.nvim_buf_set_name(buffer, "codemp::" .. name)
|
vim.api.nvim_buf_set_name(buffer, "codemp::" .. name)
|
||||||
vim.api.nvim_set_current_buf(buffer)
|
vim.api.nvim_set_current_buf(buffer)
|
||||||
end
|
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
|
-- TODO map name to uuid
|
||||||
|
|
||||||
|
@ -70,7 +75,7 @@ local function detach(name)
|
||||||
local buffer = buffer_id_map[name]
|
local buffer = buffer_id_map[name]
|
||||||
id_buffer_map[buffer] = nil
|
id_buffer_map[buffer] = nil
|
||||||
buffer_id_map[name] = 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, {})
|
vim.api.nvim_buf_delete(buffer, {})
|
||||||
|
|
||||||
print(" -- detached from buffer " .. name)
|
print(" -- detached from buffer " .. name)
|
||||||
|
@ -92,6 +97,7 @@ end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
create = create,
|
create = create,
|
||||||
|
delete = delete,
|
||||||
sync = sync,
|
sync = sync,
|
||||||
attach = attach,
|
attach = attach,
|
||||||
detach = detach,
|
detach = detach,
|
||||||
|
|
|
@ -37,6 +37,12 @@ local connected_actions = {
|
||||||
workspace.join(ws)
|
workspace.join(ws)
|
||||||
print(" >< joined workspace " .. ws)
|
print(" >< joined workspace " .. ws)
|
||||||
end,
|
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
|
-- only available if state.workspace is not nil
|
||||||
|
@ -46,6 +52,11 @@ local joined_actions = {
|
||||||
buffers.create(path)
|
buffers.create(path)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
delete = function(path)
|
||||||
|
if path == nil then error("missing buffer name") end
|
||||||
|
buffers.delete(path)
|
||||||
|
end,
|
||||||
|
|
||||||
buffers = function()
|
buffers = function()
|
||||||
workspace.open_buffer_tree()
|
workspace.open_buffer_tree()
|
||||||
end,
|
end,
|
||||||
|
@ -59,6 +70,15 @@ local joined_actions = {
|
||||||
buffers.attach(path, bang)
|
buffers.attach(path, bang)
|
||||||
end,
|
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(
|
vim.api.nvim_create_user_command(
|
||||||
|
|
Loading…
Reference in a new issue