mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-21 23:14:54 +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,70 +1,69 @@
|
|||
local path = vim.fn.stdpath('data') .. '/codemp/'
|
||||
if vim.fn.isdirectory(path) == 0 then
|
||||
vim.fn.mkdir(path, 'p')
|
||||
local rt = nil
|
||||
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')
|
||||
end
|
||||
|
||||
if native == nil then
|
||||
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 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(
|
||||
{"ExitPre"},
|
||||
{
|
||||
callback = function (_ev)
|
||||
if session.client ~= nil then
|
||||
print(" xx disconnecting codemp client")
|
||||
session.client = nil
|
||||
end
|
||||
rt:stop()
|
||||
end
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local timer_interval = vim.g.codemp_callback_interval or 100
|
||||
|
||||
if timer == nil then
|
||||
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)
|
||||
end
|
||||
|
||||
require('codemp.command')
|
||||
|
||||
return {
|
||||
native = native,
|
||||
session = session,
|
||||
buffers = require('codemp.buffers'),
|
||||
workspace = require('codemp.workspace'),
|
||||
window = require('codemp.window'),
|
||||
utils = require('codemp.utils'),
|
||||
logger = native.logger,
|
||||
rt = rt,
|
||||
callbacks_timer = timer,
|
||||
}
|
||||
end
|
||||
|
||||
-- -- 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
|
||||
local session = require('codemp.session')
|
||||
local rt = native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
||||
--native.logger(function (msg)
|
||||
-- vim.schedule(function () print(msg) end)
|
||||
--end, true)
|
||||
|
||||
vim.api.nvim_create_autocmd(
|
||||
{"ExitPre"},
|
||||
{
|
||||
callback = function (_ev)
|
||||
if session.client ~= nil then
|
||||
print(" xx disconnecting codemp client")
|
||||
session.client = nil
|
||||
end
|
||||
rt:stop()
|
||||
end
|
||||
}
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
require('codemp.command')
|
||||
|
||||
return {
|
||||
native = native,
|
||||
session = session,
|
||||
buffers = require('codemp.buffers'),
|
||||
workspace = require('codemp.workspace'),
|
||||
window = require('codemp.window'),
|
||||
utils = require('codemp.utils'),
|
||||
logger = native.logger,
|
||||
rt = rt,
|
||||
callbacks_timer = timer,
|
||||
setup = setup
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue