@@ -29,6 +29,8 @@ pub struct NeovimSession {
2929 pub io_handle : JoinHandle < std:: result:: Result < ( ) , Box < LoopError > > > ,
3030 pub neovim_process : Option < Child > ,
3131 pub stderr_task : Option < JoinHandle < Vec < String > > > ,
32+ #[ cfg( not( target_os = "windows" ) ) ]
33+ pub stdin_fd : Option < rustix:: fd:: OwnedFd > ,
3234}
3335
3436#[ cfg( debug_assertions) ]
@@ -45,6 +47,10 @@ impl NeovimSession {
4547 instance : NeovimInstance ,
4648 handler : impl Handler < Writer = NeovimWriter > ,
4749 ) -> anyhow:: Result < Self > {
50+ // This needs to be done before the process is spawned, since the file descriptors are
51+ // inherited on unix-like systems
52+ #[ cfg( not( target_os = "windows" ) ) ]
53+ let stdin_fd = instance. forward_stdin ( ) ;
4854 let ( reader, writer, stderr_reader, neovim_process) = instance. connect ( ) . await ?;
4955 // Spawn a background task to read from stderr
5056 let stderr_task = stderr_reader. map ( |reader| {
@@ -84,6 +90,8 @@ impl NeovimSession {
8490 io_handle,
8591 neovim_process,
8692 stderr_task,
93+ #[ cfg( not( target_os = "windows" ) ) ]
94+ stdin_fd,
8795 } )
8896 }
8997 }
@@ -120,7 +128,6 @@ impl NeovimInstance {
120128 mut cmd : Command ,
121129 ) -> Result < ( BoxedReader , BoxedWriter , Option < BoxedReader > , Option < Child > ) > {
122130 log:: debug!( "Starting neovim with: {cmd:?}" ) ;
123-
124131 let mut child = cmd
125132 . stdin ( Stdio :: piped ( ) )
126133 . stdout ( Stdio :: piped ( ) )
@@ -177,6 +184,20 @@ impl NeovimInstance {
177184 }
178185 }
179186
187+ #[ cfg( not( target_os = "windows" ) ) ]
188+ fn forward_stdin ( & self ) -> Option < rustix:: fd:: OwnedFd > {
189+ use std:: io:: IsTerminal ;
190+ // stdin should be forwarded only in embedded mode when stdio is piped
191+ match self {
192+ Self :: Embedded ( ..) => {
193+ let stdin = std:: io:: stdin ( ) ;
194+ let is_pipe = !stdin. is_terminal ( ) ;
195+ is_pipe. then ( || rustix:: io:: dup ( stdin) . ok ( ) ) . flatten ( )
196+ }
197+ Self :: Server { .. } => None ,
198+ }
199+ }
200+
180201 fn split (
181202 stream : impl AsyncRead + AsyncWrite + Send + Unpin + ' static ,
182203 ) -> ( BoxedReader , BoxedWriter ) {
0 commit comments