2024-09-05 05:38:13 +02:00
|
|
|
local rt = nil
|
|
|
|
local session = nil
|
|
|
|
local native = nil
|
|
|
|
local timer = nil
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-09-05 05:44:26 +02:00
|
|
|
local function setup(_opts)
|
2024-09-05 05:38:13 +02:00
|
|
|
local path = vim.fn.stdpath('data') .. '/codemp/'
|
|
|
|
if vim.fn.isdirectory(path) == 0 then
|
|
|
|
vim.fn.mkdir(path, 'p')
|
|
|
|
end
|
2024-09-05 05:44:26 +02:00
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
if native == nil then
|
|
|
|
native = require('codemp.loader').load() -- make sure we can load the native library correctly, otherwise no point going forward
|
|
|
|
--native.logger(function (msg)
|
|
|
|
-- vim.schedule(function () print(msg) end)
|
|
|
|
--end, true)
|
|
|
|
end
|
2024-08-06 02:22:02 +02:00
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
if session == nil then
|
|
|
|
session = require('codemp.session')
|
|
|
|
end
|
2024-08-08 04:34:23 +02:00
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
if rt == nil then
|
|
|
|
rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (_ev)
|
|
|
|
if session.client ~= nil then
|
|
|
|
print(" xx disconnecting codemp client")
|
|
|
|
session.client = nil
|
|
|
|
end
|
|
|
|
rt:stop()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2024-09-05 05:44:26 +02:00
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
local timer_interval = vim.g.codemp_callback_interval or 100
|
2024-09-05 05:44:26 +02:00
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
if timer == nil then
|
|
|
|
timer = vim.loop.new_timer()
|
|
|
|
timer:start(timer_interval, timer_interval, function()
|
|
|
|
while true do
|
|
|
|
local cb = native.poll_callback()
|
|
|
|
if cb == nil then break end
|
|
|
|
cb()
|
2024-08-08 04:34:23 +02:00
|
|
|
end
|
2024-09-05 05:38:13 +02:00
|
|
|
end)
|
2024-09-01 03:07:14 +02:00
|
|
|
end
|
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
require('codemp.command')
|
2024-09-01 03:07:14 +02:00
|
|
|
|
2024-09-05 05:38:13 +02:00
|
|
|
return {
|
|
|
|
native = native,
|
|
|
|
session = session,
|
|
|
|
rt = rt,
|
|
|
|
callbacks_timer = timer,
|
|
|
|
}
|
|
|
|
end
|
2024-08-06 01:11:09 +02:00
|
|
|
|
|
|
|
return {
|
2024-09-05 05:38:13 +02:00
|
|
|
setup = setup
|
2024-08-06 01:11:09 +02:00
|
|
|
}
|