feat: now codemp has a setup function

no longer sets it up itself upon requiring, mostly to just work ™️
with lazy.nvim
This commit is contained in:
əlemi 2024-09-05 05:38:13 +02:00
parent 696bd12476
commit 37005abdb2
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,35 +1,27 @@
local rt = nil
local session = nil
local native = nil
local timer = nil
local function setup(opts)
local path = vim.fn.stdpath('data') .. '/codemp/' local path = vim.fn.stdpath('data') .. '/codemp/'
if vim.fn.isdirectory(path) == 0 then if vim.fn.isdirectory(path) == 0 then
vim.fn.mkdir(path, 'p') vim.fn.mkdir(path, 'p')
end end
-- -- TODO not the best loader but a simple example? urls dont work if native == nil then
-- local host_os = vim.loop.os_uname().sysname native = require('codemp.loader').load() -- make sure we can load the native library correctly, otherwise no point going forward
-- local ext = nil
-- if host_os == "Windows" then ext = ".dll"
-- elseif host_os == "Mac" then ext = ".dylib"
-- else ext = ".so"
-- end
--
-- local shasum = nil
--
-- if vim.fn.filereadable(path .. 'native' .. ext) == 1 then
-- shasum = vim.fn.system("sha256sum " .. path .. 'native' .. ext)
-- end
--
-- local last_sum = vim.fn.system("curl -s https://codemp.alemi.dev/lib/lua/latest/sum")
--
-- if last_sum ~= shasum then
-- vim.fn.system("curl -o " .. path .. 'native' .. ext .. "https://codemp.alemi.dev/lib/lua/latest")
-- end
local native = require('codemp.loader').load() -- make sure we can load the native library correctly, otherwise no point going forward
local session = require('codemp.session')
local rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
--native.logger(function (msg) --native.logger(function (msg)
-- vim.schedule(function () print(msg) end) -- vim.schedule(function () print(msg) end)
--end, true) --end, true)
end
if session == nil then
session = require('codemp.session')
end
if rt == nil then
rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
vim.api.nvim_create_autocmd( vim.api.nvim_create_autocmd(
{"ExitPre"}, {"ExitPre"},
{ {
@ -42,10 +34,12 @@ vim.api.nvim_create_autocmd(
end end
} }
) )
end
local timer_interval = vim.g.codemp_callback_interval or 100 local timer_interval = vim.g.codemp_callback_interval or 100
local timer = vim.loop.new_timer() if timer == nil then
timer = vim.loop.new_timer()
timer:start(timer_interval, timer_interval, function() timer:start(timer_interval, timer_interval, function()
while true do while true do
local cb = native.poll_callback() local cb = native.poll_callback()
@ -53,7 +47,7 @@ timer:start(timer_interval, timer_interval, function()
cb() cb()
end end
end) end)
end
require('codemp.command') require('codemp.command')
@ -68,3 +62,8 @@ return {
rt = rt, rt = rt,
callbacks_timer = timer, callbacks_timer = timer,
} }
end
return {
setup = setup
}