codemp-nvim/lua/codemp/init.lua
alemi 216cd2d6b1
fix: codemp now uses a global
not sure how to pass the option back from setup() to window without a
global, but i'd love to...
2024-09-06 03:27:03 +02:00

64 lines
1.5 KiB
Lua

if CODEMP == nil then
---@class CodempGlobal
CODEMP = {
rt = nil,
session = nil,
native = nil,
config = {
neo_tree = false,
callback_interval = 100,
},
setup = function (opts)
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)
local path = vim.fn.stdpath('data') .. '/codemp/'
if vim.fn.isdirectory(path) == 0 then
vim.fn.mkdir(path, 'p')
end
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
--native.logger(function (msg)
-- vim.schedule(function () print(msg) end)
--end, true)
end
if CODEMP.session == nil then
CODEMP.session = require('codemp.session')
end
if CODEMP.rt == nil then
CODEMP.rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
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
if timer == nil then
timer = vim.loop.new_timer()
timer:start(CODEMP.config.timer_interval, CODEMP.config.timer_interval, function()
while true do
local cb = CODEMP.native.poll_callback()
if cb == nil then break end
cb()
end
end)
end
require('codemp.command')
return CODEMP
end,
}
end
return CODEMP