mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
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:
parent
696bd12476
commit
37005abdb2
1 changed files with 65 additions and 66 deletions
|
@ -1,36 +1,28 @@
|
||||||
local path = vim.fn.stdpath('data') .. '/codemp/'
|
local rt = nil
|
||||||
if vim.fn.isdirectory(path) == 0 then
|
local session = nil
|
||||||
|
local native = nil
|
||||||
|
local timer = nil
|
||||||
|
|
||||||
|
local function setup(opts)
|
||||||
|
local path = vim.fn.stdpath('data') .. '/codemp/'
|
||||||
|
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
|
--native.logger(function (msg)
|
||||||
-- if host_os == "Windows" then ext = ".dll"
|
-- vim.schedule(function () print(msg) end)
|
||||||
-- elseif host_os == "Mac" then ext = ".dylib"
|
--end, true)
|
||||||
-- else ext = ".so"
|
end
|
||||||
-- 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
|
if session == nil then
|
||||||
local session = require('codemp.session')
|
session = require('codemp.session')
|
||||||
local rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
end
|
||||||
--native.logger(function (msg)
|
|
||||||
-- vim.schedule(function () print(msg) end)
|
|
||||||
--end, true)
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd(
|
if rt == nil then
|
||||||
|
rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
||||||
|
vim.api.nvim_create_autocmd(
|
||||||
{"ExitPre"},
|
{"ExitPre"},
|
||||||
{
|
{
|
||||||
callback = function (_ev)
|
callback = function (_ev)
|
||||||
|
@ -41,23 +33,25 @@ vim.api.nvim_create_autocmd(
|
||||||
rt:stop()
|
rt:stop()
|
||||||
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:start(timer_interval, timer_interval, function()
|
timer = vim.loop.new_timer()
|
||||||
|
timer:start(timer_interval, timer_interval, function()
|
||||||
while true do
|
while true do
|
||||||
local cb = native.poll_callback()
|
local cb = native.poll_callback()
|
||||||
if cb == nil then break end
|
if cb == nil then break end
|
||||||
cb()
|
cb()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
require('codemp.command')
|
||||||
|
|
||||||
require('codemp.command')
|
return {
|
||||||
|
|
||||||
return {
|
|
||||||
native = native,
|
native = native,
|
||||||
session = session,
|
session = session,
|
||||||
buffers = require('codemp.buffers'),
|
buffers = require('codemp.buffers'),
|
||||||
|
@ -67,4 +61,9 @@ return {
|
||||||
logger = native.logger,
|
logger = native.logger,
|
||||||
rt = rt,
|
rt = rt,
|
||||||
callbacks_timer = timer,
|
callbacks_timer = timer,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
setup = setup
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue