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

View file

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

View file

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