2024-08-06 02:22:02 +02:00
|
|
|
local path = vim.fn.stdpath('data') .. '/codemp/'
|
|
|
|
if vim.fn.isdirectory(path) == 0 then
|
|
|
|
vim.fn.mkdir(path, 'p')
|
|
|
|
end
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-08-06 02:22:02 +02:00
|
|
|
-- -- TODO not the best loader but a simple example? urls dont work
|
|
|
|
-- local host_os = vim.loop.os_uname().sysname
|
|
|
|
-- 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
|
2024-08-24 01:56:27 +02:00
|
|
|
local session = require('codemp.session')
|
2024-08-22 22:07:00 +02:00
|
|
|
local rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
2024-08-22 03:41:22 +02:00
|
|
|
--native.logger(function (msg)
|
|
|
|
-- vim.schedule(function () print(msg) end)
|
|
|
|
--end, true)
|
2024-08-08 04:34:23 +02:00
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
2024-08-22 22:07:00 +02:00
|
|
|
callback = function (_ev)
|
2024-08-24 01:56:27 +02:00
|
|
|
if session.client ~= nil then
|
2024-08-08 04:34:23 +02:00
|
|
|
print(" xx disconnecting codemp client")
|
2024-08-24 01:56:27 +02:00
|
|
|
session.client = nil
|
2024-08-08 04:34:23 +02:00
|
|
|
end
|
2024-09-01 03:06:13 +02:00
|
|
|
rt:stop()
|
2024-08-08 04:34:23 +02:00
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
2024-08-06 01:11:09 +02:00
|
|
|
|
2024-09-01 03:07:14 +02:00
|
|
|
local timer_interval = vim.g.codemp_callback_interval or 100
|
|
|
|
|
|
|
|
local 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()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2024-08-06 18:48:27 +02:00
|
|
|
require('codemp.command')
|
2024-08-06 01:11:09 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
native = native,
|
2024-08-24 01:56:27 +02:00
|
|
|
session = session,
|
2024-08-06 18:46:22 +02:00
|
|
|
buffers = require('codemp.buffers'),
|
2024-08-06 02:21:30 +02:00
|
|
|
workspace = require('codemp.workspace'),
|
2024-08-15 03:41:28 +02:00
|
|
|
window = require('codemp.window'),
|
2024-08-06 01:11:09 +02:00
|
|
|
utils = require('codemp.utils'),
|
2024-09-01 03:07:14 +02:00
|
|
|
logger = native.logger,
|
2024-08-16 03:49:24 +02:00
|
|
|
rt = rt,
|
2024-09-01 03:07:14 +02:00
|
|
|
callbacks_timer = timer,
|
2024-08-06 01:11:09 +02:00
|
|
|
}
|