mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-25 00:44:52 +01:00
fix: setup plugin in setup() fn
so that configuration can reach logger and callbacks
This commit is contained in:
parent
f3a7e1ea1c
commit
d8990452d0
1 changed files with 28 additions and 32 deletions
|
@ -10,7 +10,7 @@ if CODEMP == nil then
|
||||||
---@field available WorkspaceReference[] available workspaces to connect to
|
---@field available WorkspaceReference[] available workspaces to connect to
|
||||||
---@field timer? any libuv timer
|
---@field timer? any libuv timer
|
||||||
---@field config Config codemp configuration
|
---@field config Config codemp configuration
|
||||||
---@field setup fun(opts: Config): nil update codemp configuration
|
---@field setup fun(opts: Config): nil update config and setup plugin
|
||||||
CODEMP = {
|
CODEMP = {
|
||||||
rt = nil,
|
rt = nil,
|
||||||
native = nil,
|
native = nil,
|
||||||
|
@ -25,20 +25,9 @@ if CODEMP == nil then
|
||||||
},
|
},
|
||||||
setup = function (opts)
|
setup = function (opts)
|
||||||
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)
|
CODEMP.config = vim.tbl_extend('force', CODEMP.config, opts)
|
||||||
end
|
-- register logger
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
if CODEMP.native == nil then
|
|
||||||
CODEMP.native = require('codemp.loader').load() -- make sure we can load the native library correctly, otherwise no point going forward
|
|
||||||
if CODEMP.native == nil then
|
|
||||||
print(" !! could not load native bindings, try reloading")
|
|
||||||
return CODEMP
|
|
||||||
end
|
|
||||||
CODEMP.native.logger(print, CODEMP.config.debug)
|
CODEMP.native.logger(print, CODEMP.config.debug)
|
||||||
end
|
-- start background runtime, with stop event
|
||||||
|
|
||||||
if CODEMP.rt == nil then
|
|
||||||
CODEMP.rt = CODEMP.native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
CODEMP.rt = CODEMP.native.spawn_runtime_driver() -- spawn thread to drive tokio runtime
|
||||||
vim.api.nvim_create_autocmd(
|
vim.api.nvim_create_autocmd(
|
||||||
{"ExitPre"},
|
{"ExitPre"},
|
||||||
|
@ -46,15 +35,13 @@ if CODEMP.rt == nil then
|
||||||
callback = function (_ev)
|
callback = function (_ev)
|
||||||
if CODEMP.client ~= nil then
|
if CODEMP.client ~= nil then
|
||||||
print(" xx disconnecting codemp client")
|
print(" xx disconnecting codemp client")
|
||||||
CODEMP.client = nil
|
CODEMP.client = nil -- drop reference so it gets garbage collected
|
||||||
end
|
end
|
||||||
CODEMP.rt:stop()
|
CODEMP.rt:stop()
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
|
||||||
|
|
||||||
if CODEMP.timer == nil then
|
|
||||||
CODEMP.timer = vim.loop.new_timer()
|
CODEMP.timer = vim.loop.new_timer()
|
||||||
CODEMP.timer:start(CODEMP.config.timer_interval, CODEMP.config.timer_interval, function()
|
CODEMP.timer:start(CODEMP.config.timer_interval, CODEMP.config.timer_interval, function()
|
||||||
while true do
|
while true do
|
||||||
|
@ -65,7 +52,16 @@ if CODEMP.timer == nil then
|
||||||
end)
|
end)
|
||||||
|
|
||||||
require('codemp.command') -- not really related but should only happen once
|
require('codemp.command') -- not really related but should only happen once
|
||||||
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if CODEMP.native == nil then
|
||||||
|
CODEMP.native = require('codemp.loader').load() -- make sure we can load the native library correctly, otherwise no point going forward
|
||||||
|
if CODEMP.native == nil then
|
||||||
|
print(" !! could not load native bindings, try reloading")
|
||||||
|
return CODEMP
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return CODEMP
|
return CODEMP
|
||||||
|
|
Loading…
Reference in a new issue