Skip to content

fix(neovim): relax CWD matching for instance discovery and fix active visual selection capture#63

Merged
aliou merged 1 commit intoaliou:mainfrom
w-winter:feat/neovim-child-dirs
Mar 5, 2026
Merged

fix(neovim): relax CWD matching for instance discovery and fix active visual selection capture#63
aliou merged 1 commit intoaliou:mainfrom
w-winter:feat/neovim-child-dirs

Conversation

@w-winter
Copy link
Contributor

@w-winter w-winter commented Mar 4, 2026

The Neovim extension's instance discovery required an exact CWD match between Pi and Neovim, which meant opening Neovim in a project subdirectory (e.g. ./src) while Pi ran from the project root would silently fail to connect. Separately, querying the editor's visual selection while the user was still in visual mode returned stale data from the previous selection because the Lua plugin read '</'> marks that only update after exiting visual mode.

This makes discovery a more flexible and resilient by falling back to child-directory CWD matching (with symlink resolution and proximity sorting), and it fixes the selection capture to use the live v/. marks. It also hardens the lockfile handling that the broader scan now touches: filename-pattern filtering, schema validation before deletion, and correct EPERM handling in process-liveness checks.

Summary of changes:

  • discovery: fall back to Neovim instances whose CWD is a child of Pi's CWD when no exact hash match exists, sorted by directory depth (closest first)
  • discovery: restrict lockfile candidates to the {8-hex}-{pid}.json naming convention and validate socket/cwd/pid schema before accepting or deleting files
  • discovery: resolve symlinks via fs.realpathSync.native() so symlinked project roots still match
  • liveness: treat EPERM from process.kill(pid, 0) as "process exists" instead of deleting the lockfile
  • selection (Lua): switch from getpos("'<")/getpos("'>") to getpos("v")/getpos(".") for live visual-mode capture, with start/end normalization for backwards selections
  • selection (Lua): skip selection capture when the source window differs from the current window to prevent mismatched payloads
  • tests: add nvim.test.ts covering exact-vs-related discovery, lockfile safety, EPERM branch, and symlink matching
  • config: include integrations/**/*.test.ts in vitest config
  • docs: add child-directory discovery note to README troubleshooting section

@aliou
Copy link
Owner

aliou commented Mar 5, 2026

LGTM! Thanks for taking the time, let me know if the demo works better this time!

Auto review: https://pi.dev/session/#a1fb4f54914dc4a06c2b2e823826fbfa

@aliou aliou merged commit 4182795 into aliou:main Mar 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants