codemp-nvim/lua/codemp/init.lua

65 lines
1.3 KiB
Lua
Raw Normal View History

local rt = nil
local session = nil
local native = nil
local timer = nil
2024-09-05 05:44:26 +02:00
local function setup(_opts)
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
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
if session == nil then
session = require('codemp.session')
end
2024-08-08 04:34:23 +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
local timer_interval = vim.g.codemp_callback_interval or 100
2024-09-05 05:44:26 +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
end)
end
require('codemp.command')
return {
native = native,
session = session,
rt = rt,
callbacks_timer = timer,
}
end
return {
setup = setup
}