mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
feat: async connecting and reloading workspaces
This commit is contained in:
parent
db24f06633
commit
532733ac76
3 changed files with 31 additions and 30 deletions
|
@ -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
|
window.update()
|
||||||
user = vim.g.codemp_username or vim.fn.input("username > ", "")
|
print(" ++ connected to " .. host .. " as " .. username)
|
||||||
password = vim.g.codemp_password or vim.fn.input("password > ", "")
|
vim.schedule(function () workspace.list(client) end)
|
||||||
end
|
end)
|
||||||
session.client = native.connect(host, user, password):await()
|
|
||||||
session.available = workspace.list(session.client)
|
|
||||||
window.update()
|
|
||||||
print(" ++ connected to " .. host .. " as " .. user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue