generated from eblume/project-template
heph.nvim: plug-and-play managed daemon (autostart, self-heal, client/server guardrail)
The plugin now manages its own hephd by default (autostart = true): if nothing is serving the socket it spawns a local daemon against the default XDG paths, kills only what it spawned on VimLeavePre, and self-heals — rpc.call retries once through a respawn hook when the connection drops (the prior owner releases the DB lock on exit, so a respawn can claim it). - daemon.ensure() connects to an already-running daemon (any mode) or spawns one we own; stop_spawned()/is_managed() track lifecycle. - A server/client daemon you started is always respected (spawn only when nothing serves the socket). autostart = false → connect-only, warns/errors if down, and clears the self-heal hook so it fails loudly. - config: autostart defaults true; new `db` option; $HEPH_SOCKET / $HEPH_DB fallbacks isolate a dev Neovim onto a separate daemon + DB. e2e: managed_daemon_spec covers autostart spawn, self-heal-after-kill, and connect-only error. 10 specs green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fef0e82d26
commit
e3db2ac550
11 changed files with 277 additions and 18 deletions
|
|
@ -14,15 +14,44 @@ M.config = nil
|
|||
function M.setup(opts)
|
||||
local cfg = vim.tbl_deep_extend("force", config.defaults, opts or {})
|
||||
cfg.socket = config.resolve_socket(cfg.socket)
|
||||
cfg.db = config.resolve_db(cfg.db)
|
||||
M.config = cfg
|
||||
|
||||
require("heph.rpc").setup(cfg.socket)
|
||||
local rpc = require("heph.rpc")
|
||||
local daemon = require("heph.daemon")
|
||||
rpc.setup(cfg.socket)
|
||||
|
||||
if cfg.autostart then
|
||||
local ok = require("heph.daemon").wait_ready(cfg.socket, 500)
|
||||
-- Plug-and-play: bring up a managed local daemon if none is serving, and
|
||||
-- self-heal a dropped connection on later calls.
|
||||
local ok = pcall(daemon.ensure, {
|
||||
socket = cfg.socket,
|
||||
db = cfg.db,
|
||||
bin = cfg.bin,
|
||||
autostart = true,
|
||||
})
|
||||
if not ok then
|
||||
require("heph.daemon").spawn({ bin = cfg.bin, socket = cfg.socket, db = nil })
|
||||
require("heph.daemon").wait_ready(cfg.socket, 5000)
|
||||
require("heph.util").notify(
|
||||
"could not start hephd; will retry on first use",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
rpc.set_respawn(function()
|
||||
pcall(daemon.ensure, {
|
||||
socket = cfg.socket,
|
||||
db = cfg.db,
|
||||
bin = cfg.bin,
|
||||
autostart = true,
|
||||
})
|
||||
end)
|
||||
else
|
||||
-- Explicit architecture: connect only, never spawn over the user's daemon.
|
||||
rpc.set_respawn(nil)
|
||||
if not daemon.ensure({ socket = cfg.socket, autostart = false }) then
|
||||
require("heph.util").notify(
|
||||
"no hephd reachable at " .. cfg.socket .. " (autostart disabled)",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue