2024-09-17 17:26:23 +02:00
|
|
|
---@class WorkspaceReference
|
|
|
|
---@field name string
|
|
|
|
---@field owned boolean
|
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
if CODEMP == nil then
|
|
|
|
---@class CodempGlobal
|
2024-09-17 17:26:23 +02:00
|
|
|
---@field rt? RuntimeDriver background codemp runtime
|
|
|
|
---@field client? Client currently connected client
|
|
|
|
---@field workspace? Workspace current active workspace
|
2024-09-17 17:58:32 +02:00
|
|
|
---@field available WorkspaceReference[] available workspaces to connect to
|
2024-09-17 17:26:23 +02:00
|
|
|
---@field timer? any libuv timer
|
|
|
|
---@field config Config codemp configuration
|
|
|
|
---@field setup fun(opts: Config): nil update codemp configuration
|
2024-09-06 03:27:03 +02:00
|
|
|
CODEMP = {
|
|
|
|
rt = nil,
|
|
|
|
native = nil,
|
2024-09-06 03:44:18 +02:00
|
|
|
timer = nil,
|
2024-09-17 17:58:32 +02:00
|
|
|
available = {},
|
2024-09-06 03:27:03 +02:00
|
|
|
config = {
|
|
|
|
neo_tree = false,
|
2024-09-16 04:13:54 +02:00
|
|
|
timer_interval = 20,
|
2024-09-06 03:53:52 +02:00
|
|
|
debug = false,
|
2024-09-17 17:26:23 +02:00
|
|
|
username = "",
|
|
|
|
password = "",
|
2024-09-06 03:27:03 +02:00
|
|
|
},
|
|
|
|
setup = function (opts)
|
|
|
|
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)
|
2024-09-13 23:46:59 +02:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-09-13 23:46:59 +02:00
|
|
|
if CODEMP.native == nil then
|
|
|
|
CODEMP.native = require('codemp.loader').load() -- make sure we can load the native library correctly, otherwise no point going forward
|
2024-09-14 23:57:47 +02:00
|
|
|
if CODEMP.native == nil then
|
|
|
|
print(" !! could not load native bindings, try reloading")
|
2024-09-17 19:48:53 +02:00
|
|
|
return CODEMP
|
2024-09-14 23:57:47 +02:00
|
|
|
end
|
2024-09-17 19:48:53 +02:00
|
|
|
CODEMP.native.logger(print, CODEMP.config.debug)
|
2024-09-13 23:46:59 +02:00
|
|
|
end
|
2024-09-05 05:44:26 +02:00
|
|
|
|
2024-09-13 23:46:59 +02:00
|
|
|
if CODEMP.rt == nil then
|
|
|
|
CODEMP.rt = CODEMP.native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
2024-09-17 17:26:23 +02:00
|
|
|
if CODEMP.client ~= nil then
|
2024-09-13 23:46:59 +02:00
|
|
|
print(" xx disconnecting codemp client")
|
2024-09-17 17:26:23 +02:00
|
|
|
CODEMP.client = nil
|
2024-09-13 23:46:59 +02:00
|
|
|
end
|
|
|
|
CODEMP.rt:stop()
|
2024-08-08 04:34:23 +02:00
|
|
|
end
|
2024-09-13 23:46:59 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2024-09-01 03:07:14 +02:00
|
|
|
|
2024-09-13 23:46:59 +02:00
|
|
|
if CODEMP.timer == nil then
|
|
|
|
CODEMP.timer = vim.loop.new_timer()
|
|
|
|
CODEMP.timer:start(CODEMP.config.timer_interval, CODEMP.config.timer_interval, function()
|
|
|
|
while true do
|
2024-09-17 17:58:32 +02:00
|
|
|
local cb, arg = CODEMP.native.poll_callback()
|
2024-09-13 23:46:59 +02:00
|
|
|
if cb == nil then break end
|
2024-09-17 17:58:32 +02:00
|
|
|
vim.schedule(function() cb(arg) end)
|
2024-09-13 23:46:59 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
require('codemp.command') -- not really related but should only happen once
|
2024-09-05 05:38:13 +02:00
|
|
|
end
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-09-13 23:46:59 +02:00
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
return CODEMP
|