2024-09-06 03:27:03 +02:00
|
|
|
if CODEMP == nil then
|
|
|
|
---@class CodempGlobal
|
|
|
|
CODEMP = {
|
|
|
|
rt = nil,
|
|
|
|
session = nil,
|
|
|
|
native = nil,
|
2024-09-06 03:44:18 +02:00
|
|
|
timer = nil,
|
2024-09-06 03:27:03 +02:00
|
|
|
config = {
|
|
|
|
neo_tree = false,
|
2024-09-06 03:35:39 +02:00
|
|
|
timer_interval = 100,
|
2024-09-06 03:53:52 +02:00
|
|
|
debug = false,
|
2024-09-06 03:27:03 +02:00
|
|
|
},
|
|
|
|
setup = function (opts)
|
|
|
|
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-09-06 03:27:03 +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-06 03:34:08 +02:00
|
|
|
--CODEMP.native.logger(function (msg)
|
2024-09-06 03:27:03 +02:00
|
|
|
-- vim.schedule(function () print(msg) end)
|
|
|
|
--end, true)
|
|
|
|
end
|
2024-08-08 04:34:23 +02:00
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
if CODEMP.session == nil then
|
|
|
|
CODEMP.session = require('codemp.session')
|
|
|
|
end
|
2024-09-05 05:44:26 +02:00
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
if CODEMP.rt == nil then
|
2024-09-06 03:34:08 +02:00
|
|
|
CODEMP.rt = CODEMP.native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
2024-09-06 03:27:03 +02:00
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
|
|
|
if CODEMP.session.client ~= nil then
|
|
|
|
print(" xx disconnecting codemp client")
|
|
|
|
CODEMP.session.client = nil
|
|
|
|
end
|
|
|
|
CODEMP.rt:stop()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2024-09-05 05:44:26 +02:00
|
|
|
|
2024-09-06 03:44:18 +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()
|
2024-09-06 03:27:03 +02:00
|
|
|
while true do
|
|
|
|
local cb = CODEMP.native.poll_callback()
|
|
|
|
if cb == nil then break end
|
|
|
|
cb()
|
|
|
|
end
|
|
|
|
end)
|
2024-09-06 19:25:15 +02:00
|
|
|
|
|
|
|
require('codemp.command') -- not really related but should only happen once
|
2024-08-08 04:34:23 +02:00
|
|
|
end
|
2024-09-01 03:07:14 +02:00
|
|
|
|
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
return CODEMP
|
|
|
|
end,
|
2024-09-05 05:38:13 +02:00
|
|
|
}
|
|
|
|
end
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-09-06 03:27:03 +02:00
|
|
|
return CODEMP
|