feat: async connecting and reloading workspaces

This commit is contained in:
əlemi 2024-08-25 03:50:52 +02:00
parent db24f06633
commit 532733ac76
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 31 additions and 30 deletions

View file

@ -3,20 +3,16 @@ local window = require("codemp.window")
local session = require("codemp.session") local session = require("codemp.session")
local workspace = require("codemp.workspace") local workspace = require("codemp.workspace")
local function connect(host, bang) local function connect(host, username, password)
if host == nil then host = 'http://codemp.alemi.dev:50054' end if host == nil then host = 'http://codemp.dev:50053' end
local user, password if username == nil then username = vim.g.codemp_username or vim.fn.input("username > ", "") end
if bang then -- ignore configured values if password == nil then password = vim.g.codemp_password or vim.fn.input("password > ", "") end
user = vim.fn.input("username > ", "") native.connect(host, username, password):and_then(function (client)
password = vim.fn.input("password > ", "") session.client = client
else
user = vim.g.codemp_username or vim.fn.input("username > ", "")
password = vim.g.codemp_password or vim.fn.input("password > ", "")
end
session.client = native.connect(host, user, password):await()
session.available = workspace.list(session.client)
window.update() window.update()
print(" ++ connected to " .. host .. " as " .. user) print(" ++ connected to " .. host .. " as " .. username)
vim.schedule(function () workspace.list(client) end)
end)
end end
return { return {

View file

@ -42,6 +42,7 @@ local connected_actions = {
start = function(ws) start = function(ws)
if ws == nil then error("missing workspace name") end if ws == nil then error("missing workspace name") end
session.client:create_workspace(ws):await() session.client:create_workspace(ws):await()
vim.schedule(function () workspace.list(session.client) end)
print(" <> created workspace " .. ws) print(" <> created workspace " .. ws)
end, end,

View file

@ -5,23 +5,26 @@ local window = require('codemp.window')
local user_hl = {} local user_hl = {}
local function fetch_workspaces_list(client) local function fetch_workspaces_list()
local new_list = {} local new_list = {}
local owned = client:list_workspaces(true, false):await() session.client:list_workspaces(true, false):and_then(function (owned)
for _, ws in pairs(owned) do for _, ws in pairs(owned) do
table.insert(new_list, { table.insert(new_list, {
name = ws, name = ws,
owned = true, owned = true,
}) })
end end
local invited = client:list_workspaces(false, true):await() session.client:list_workspaces(false, true):and_then(function (invited)
for _, ws in pairs(invited) do for _, ws in pairs(invited) do
table.insert(new_list, { table.insert(new_list, {
name = ws, name = ws,
owned = false, owned = false,
}) })
end end
return new_list session.available = new_list
window.update()
end)
end)
end end
---@param ws Workspace ---@param ws Workspace
@ -102,6 +105,7 @@ local function join(workspace)
end) end)
session.workspace = ws session.workspace = ws
window.update()
return ws return ws
end end