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-08 04:34:23 +02:00
|
|
|
local state = require('codemp.state')
|
|
|
|
native.runtime_drive_forever() -- spawn thread to drive tokio runtime
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{"ExitPre"},
|
|
|
|
{
|
|
|
|
callback = function (ev)
|
|
|
|
if state.client ~= nil then
|
|
|
|
print(" xx disconnecting codemp client")
|
|
|
|
native.close_client(state.client.id)
|
|
|
|
state.client = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
2024-08-06 01:11:09 +02:00
|
|
|
|
|
|
|
-- TODO nvim docs say that we should stop all threads before exiting nvim
|
|
|
|
-- but we like to live dangerously (:
|
|
|
|
vim.loop.new_thread({}, function()
|
2024-08-06 23:03:46 +02:00
|
|
|
vim.loop.sleep(1000) -- allow user to setup their own logger options
|
2024-08-06 02:22:02 +02:00
|
|
|
local _codemp = require('codemp.loader').load()
|
2024-08-06 23:03:46 +02:00
|
|
|
_codemp.setup_logger()
|
|
|
|
local logger = _codemp.get_logger()
|
2024-08-06 01:11:09 +02:00
|
|
|
while true do
|
|
|
|
print(logger:recv())
|
|
|
|
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-08 04:34:23 +02:00
|
|
|
state = require('codemp.state'),
|
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-06 01:11:09 +02:00
|
|
|
utils = require('codemp.utils'),
|
|
|
|
async = require('codemp.async'),
|
|
|
|
}
|