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
|
2024-09-25 04:00:46 +02:00
|
|
|
---@field following string | nil
|
|
|
|
---@field ignore_following_action boolean TODO a more elegant solution?
|
2024-09-17 22:12:15 +02:00
|
|
|
---@field setup fun(opts: Config): nil update config and setup plugin
|
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-25 04:00:46 +02:00
|
|
|
following = nil,
|
|
|
|
ignore_following_action = false,
|
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-17 22:12:15 +02:00
|
|
|
-- register logger
|
2024-09-17 23:49:58 +02:00
|
|
|
CODEMP.native.setup_tracing(CODEMP.config.debug_file or print, CODEMP.config.debug)
|
2024-09-17 22:12:15 +02:00
|
|
|
-- start background runtime, with stop event
|
2024-09-17 23:48:53 +02:00
|
|
|
CODEMP.rt = CODEMP.native.setup_driver() -- spawn thread to drive tokio runtime
|
2024-09-17 22:12:15 +02:00
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
2024-10-12 23:24:33 +02:00
|
|
|
if CODEMP.workspace ~= nil then
|
2024-10-26 18:15:30 +02:00
|
|
|
print(" xx leaving workspace " .. CODEMP.workspace:id())
|
2024-10-12 23:24:33 +02:00
|
|
|
require('codemp.workspace').leave()
|
|
|
|
end
|
2024-09-17 22:12:15 +02:00
|
|
|
if CODEMP.client ~= nil then
|
|
|
|
print(" xx disconnecting codemp client")
|
|
|
|
CODEMP.client = nil -- drop reference so it gets garbage collected
|
|
|
|
end
|
|
|
|
CODEMP.rt:stop()
|
2024-10-12 23:27:08 +02:00
|
|
|
require('codemp.window').update()
|
2024-09-17 22:12:15 +02:00
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
CODEMP.timer = vim.loop.new_timer()
|
|
|
|
CODEMP.timer:start(CODEMP.config.timer_interval, CODEMP.config.timer_interval, function()
|
|
|
|
while true do
|
2024-09-18 00:39:52 +02:00
|
|
|
local cb, arg = CODEMP.native.poll_callback()
|
|
|
|
if cb == nil then break end
|
|
|
|
if cb == false then
|
|
|
|
error(arg)
|
2024-09-18 00:28:01 +02:00
|
|
|
else
|
|
|
|
vim.schedule(function() cb(arg) end)
|
|
|
|
end
|
2024-09-17 22:12:15 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
require('codemp.command') -- not really related but should only happen once
|
2024-09-25 02:11:58 +02:00
|
|
|
require('codemp.utils').setup_colors() -- create highlight groups for users
|
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-13 23:46:59 +02:00
|
|
|
end
|
2024-09-01 03:07:14 +02:00
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
return CODEMP
|