fix: always leave workspace before disconnecting

This commit is contained in:
əlemi 2024-10-12 23:24:33 +02:00
parent e0c1069939
commit 594330c721
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 9 additions and 0 deletions

View file

@ -80,6 +80,10 @@ local connected_actions = {
end,
disconnect = function()
if CODEMP.workspace ~= nil then
print(" xx leaving workspace " .. CODEMP.workspace.name)
workspace.leave()
end
print(" xx disconnecting client " .. CODEMP.client.id)
CODEMP.client = nil -- should drop and thus close everything
collectgarbage("collect") -- make sure we drop

View file

@ -37,6 +37,10 @@ if CODEMP == nil then
{"ExitPre"},
{
callback = function (_ev)
if CODEMP.workspace ~= nil then
print(" xx leaving workspace " .. CODEMP.workspace.name)
require('codemp.workspace').leave()
end
if CODEMP.client ~= nil then
print(" xx disconnecting codemp client")
CODEMP.client = nil -- drop reference so it gets garbage collected

View file

@ -116,6 +116,7 @@ M.delete = function(state, path, extra)
if selected.type == "title" then
vim.ui.input({ prompt = "disconnect from server?" }, function(choice)
if not choice or not vim.startswith(string.lower(choice), "y") then return end
if CODEMP.workspace ~= nil then ws_manager.leave() end
CODEMP.client = nil
collectgarbage("collect") -- to make sure we drop the reference and disconnect
end)