Skip to content

Add support for nvim servers running over TCP#77

Open
adamnew123456 wants to merge 1 commit intosubnut:mainfrom
adamnew123456:tcp-nvim-server
Open

Add support for nvim servers running over TCP#77
adamnew123456 wants to merge 1 commit intosubnut:mainfrom
adamnew123456:tcp-nvim-server

Conversation

@adamnew123456
Copy link

@adamnew123456 adamnew123456 commented Mar 5, 2026

pynvim natively supports four methods for attaching to nvim:

@overload
def attach(session_type: Literal['tcp'], address: str, port: int = 7450) -> Nvim: ...

@overload
def attach(session_type: Literal['socket'], *, path: str) -> Nvim: ...

@overload
def attach(session_type: Literal['child'], *, argv: List[str]) -> Nvim: ...

@overload
def attach(session_type: Literal['stdio']) -> Nvim: ...

child and stdio aren't really relevant for nvim-ghost since it runs the WebSocket server as a daemon, and separate nvim instances share it by sending focus messages. Currently the helper script assumes socket, but tcp is also an option (I use it to make my config more cross-platform).

The only trick is that you have to guess which transport is intended by parsing $NVIM. But nvim also does this when it interprets the user's --listen config, I just borrowed the algorithm:

https://github.com/neovim/neovim/blob/d9d8c660fd5559d928c8870a21970a375674e310/src/nvim/event/socket.c#L46

pynvim supports this, we just have to perform the right invocation
depending upon the format of the address. nvim itself does this in a
straightforward way so we can do the same thing for consistency.

https://github.com/neovim/neovim/blob/d9d8c660fd5559d928c8870a21970a375674e310/src/nvim/event/socket.c#L46
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.

1 participant