feat: pidfile-based socket discovery (#47, phase 1)#53
Merged
Conversation
Each nvim instance running setup() now self-registers its RPC socket and cwd to ~/.local/state/code-preview/sockets/<pid>. nvim-socket.sh checks this directory first, falling back to the existing /var/folders, /tmp, and XDG_RUNTIME_DIR globs for nvim instances that haven't been restarted. Why: the glob-based discovery is OS-specific (relies on lsof, compgen, kill -0, /proc) and is the main blocker for Windows support tracked in \#46. The pidfile is computable from any platform without those tools and contains the cwd directly, eliminating the lsof lookup that today gives the startup cwd rather than the user's current :cd. Behavior preserved: - Multi-instance routing via the same match-or-parent-cwd rule - NVIM_LISTEN_ADDRESS override - Single-instance / fallback case (legacy globs still run when no pidfile matches) Behavior improved: - Liveness check is socket-connect, not kill -0 — catches hung nvim - cwd is read live from nvim, refreshed on DirChanged This is phase 1 of a four-phase migration to Lua-based orchestration. The pidfile itself is permanent; nvim-socket.sh will be removed in a later phase when orchestration moves entirely into Lua. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of #47 — replaces OS-specific socket-glob discovery with a self-registered pidfile that each nvim writes on
setup().Summary
code-preview.setup()writes~/.local/state/code-preview/sockets/<pid>containing its RPC socket path and current cwd (two lines).bin/nvim-socket.shchecks this directory first, validates the socket is responsive, applies the same match-or-parent-cwd rule as before, and falls back to the existing/var/folders//tmp/$XDG_RUNTIME_DIRdiscovery if no pidfile matches.:CodePreviewStatusand:checkhealth code-previewboth surface pidfile state.Why
The glob-based discovery relies on
lsof,compgen,kill -0, and/proc— none of which exist natively on Windows. This is the main blocker for #46. The pidfile is computable from any platform and stores cwd directly, eliminating thelsoflookup that today returns the process's startup cwd rather than the user's current:cd.Behavior preserved
NVIM_LISTEN_ADDRESSoverride (still checked first)Behavior improved
kill -0— catches hung nvim with a live PIDDirChanged, so:cd-ing to a different project routes correctly without restarting nvimScope
This is phase 1 of a four-phase migration. The pidfile itself is permanent — phases 2–4 (orchestration porting to Lua) will continue to read from the same pidfile dir.
nvim-socket.shwill be removed entirely in a later phase.Out of scope here:
-Stest, path separators) — not worth it on a file we're deletingTest plan
setup()DirChangedrefreshes cwd line on:cdVimLeavePreremoves the pidfile on:qanvim-socket.shresolves the right socket via pidfile (single instance)cd repo/luastill resolves to nvim opened atrepo/:CodePreviewStatusshows pidfile path:checkhealth code-previewshows pidfile registration status🤖 Generated with Claude Code