I made pyimp.nvim — a tiny ty sidecar that updates Python imports when renaming files/packages in Neovim
Hey folks,
I’ve been trying out ty as my Python LSP in Neovim: https://github.com/astral-sh/ty
It already supports normal symbol rename, but it doesn’t currently implement file/package rename refactoring — i.e. when you rename:main_app/modules/auth -> main_app/modules/auth_renamed
your imports don’t get updated automatically.
So I made a small plugin: https://github.com/AlexanderFarkas/pyimp.nvim
pyimp.nvim starts a Rust LSP sidecar next to an already-running ty client. It listens for workspace/willRenameFiles and returns a WorkspaceEdit that updates Python imports before the file/directory is physically renamed.
It supports:
- file renames
- package/directory renames
- absolute imports
- relative imports
Fun part: I use LazyVim and during the testing I discovered one Snacks-specific caveat: Snacks applies willRenameFiles edits before renaming, but Neovim leaves edits in hidden buffers instead of writing them to disk. And there is no way to hook into this process. For that I also extracted a tiny companion plugin: https://github.com/AlexanderFarkas/snacks-rename-fix.nvim
It patches snacks.rename to persist willRenameFiles edits before the actual filesystem rename. It has two modes:
- smart: loaded buffers are edited/saved via Neovim, unloaded files are patched directly on disk
- write_all: use normal apply_workspace_edit(), then run :wall
I tested this on a real project rename with a few hundred import edits and it completed quickly.
Would love feedback, especially from people using ty, or working on large Python monorepos in Neovim.