@@ -19,7 +19,8 @@ const ERR_TERMINAL_NOT_FOUND: &str = "Could not find any suitable terminal";
1919
2020const VAR_CLASSNAME : & str = "{CLASSNAME}" ;
2121const VAR_ADDRESS : & str = "{ADDR}" ;
22- const VAR_REMOTE_CMD : & str = "{REMOTE_CMD}" ;
22+ const VAR_LINE : & str = "{LINE}" ;
23+ const VAR_FILE : & str = "{FILE}" ;
2324
2425#[ derive( Debug ) ]
2526struct Launcher ( PathBuf , Vec < String > ) ;
@@ -106,7 +107,8 @@ fn create_launcher(cfg: &PluginConfig, nvim: &String) -> Result<Launcher> {
106107 args. push ( VAR_ADDRESS . to_string ( ) ) ;
107108
108109 args. push ( "--remote" . to_string ( ) ) ;
109- args. push ( VAR_REMOTE_CMD . to_string ( ) ) ;
110+ args. push ( VAR_LINE . to_string ( ) ) ;
111+ args. push ( VAR_FILE . to_string ( ) ) ;
110112
111113 Ok ( Launcher ( executable. clone ( ) , args) )
112114 }
@@ -151,7 +153,8 @@ fn create_launcher(cfg: &PluginConfig, nvim: &String) -> Result<Launcher> {
151153 args. push ( VAR_ADDRESS . to_string ( ) ) ;
152154
153155 args. push ( "--remote" . to_string ( ) ) ;
154- args. push ( VAR_REMOTE_CMD . to_string ( ) ) ;
156+ args. push ( VAR_LINE . to_string ( ) ) ;
157+ args. push ( VAR_FILE . to_string ( ) ) ;
155158
156159 Some ( Launcher ( exe, args) )
157160 } else {
@@ -194,7 +197,8 @@ fn create_launcher(cfg: &PluginConfig, nvim: &String) -> Result<Launcher> {
194197 args. push ( VAR_ADDRESS . to_string ( ) ) ;
195198
196199 args. push ( "--remote" . to_string ( ) ) ;
197- args. push ( VAR_REMOTE_CMD . to_string ( ) ) ;
200+ args. push ( VAR_LINE . to_string ( ) ) ;
201+ args. push ( VAR_FILE . to_string ( ) ) ;
198202
199203 return Some ( Launcher ( path, args) ) ;
200204 }
@@ -223,7 +227,8 @@ fn create_launcher(cfg: &PluginConfig, nvim: &String) -> Result<Launcher> {
223227 args. push ( VAR_ADDRESS . to_string ( ) ) ;
224228
225229 args. push ( "--remote" . to_string ( ) ) ;
226- args. push ( VAR_REMOTE_CMD . to_string ( ) ) ;
230+ args. push ( VAR_LINE . to_string ( ) ) ;
231+ args. push ( VAR_FILE . to_string ( ) ) ;
227232
228233 return Some ( Launcher ( path, args) ) ;
229234 }
@@ -260,7 +265,13 @@ fn create_launcher(cfg: &PluginConfig, nvim: &String) -> Result<Launcher> {
260265 }
261266}
262267
263- fn nvim_open_file_remote ( nvim : & str , server : & str , remote_cmd : & str ) -> Result < ( ) > {
268+ fn nvim_open_file_remote ( nvim : & str , server : & str , file : & str , line : Option < usize > ) -> Result < ( ) > {
269+ let remote_cmd = if let Some ( line) = line {
270+ format ! ( "+{line} {file}" )
271+ } else {
272+ file. to_string ( )
273+ } ;
274+
264275 tracing:: debug!( "Open '{remote_cmd}' via socket: {server}" ) ;
265276
266277 let out = Command :: new ( nvim)
@@ -277,7 +288,13 @@ fn nvim_open_file_remote(nvim: &str, server: &str, remote_cmd: &str) -> Result<(
277288 Ok ( ( ) )
278289}
279290
280- fn run_fsock ( launcher : Launcher , nvim : & str , root_dir : & Path , remote_cmd : & str ) -> Result < ( ) > {
291+ fn run_fsock (
292+ launcher : Launcher ,
293+ nvim : & str ,
294+ root_dir : & Path ,
295+ file : & str ,
296+ line : Option < usize > ,
297+ ) -> Result < ( ) > {
281298 let socket_file = utils:: runtime_dir (
282299 root_dir
283300 . to_str ( )
@@ -302,7 +319,8 @@ fn run_fsock(launcher: Launcher, nvim: &str, root_dir: &Path, remote_cmd: &str)
302319 socket_file
303320 . to_str ( )
304321 . context ( "could not convert path to string" ) ?,
305- remote_cmd,
322+ file,
323+ line,
306324 ) {
307325 tracing:: error!( "Failed to communicate with neovim server: {err:?}" ) ;
308326
@@ -317,7 +335,13 @@ fn run_fsock(launcher: Launcher, nvim: &str, root_dir: &Path, remote_cmd: &str)
317335 Ok ( ( ) )
318336}
319337
320- fn run_netsock ( launcher : Launcher , nvim : & str , root_dir : & Path , remote_cmd : & str ) -> Result < ( ) > {
338+ fn run_netsock (
339+ launcher : Launcher ,
340+ nvim : & str ,
341+ root_dir : & Path ,
342+ file : & str ,
343+ line : Option < usize > ,
344+ ) -> Result < ( ) > {
321345 let port_file = utils:: runtime_dir (
322346 root_dir
323347 . to_str ( )
@@ -338,7 +362,7 @@ fn run_netsock(launcher: Launcher, nvim: &str, root_dir: &Path, remote_cmd: &str
338362 if is_port_in_use ( port) {
339363 // if we couldnt communicate with the server despite existing apparently
340364 // delete it and start a new instance
341- if let Err ( err) = nvim_open_file_remote ( nvim, & socket, remote_cmd ) {
365+ if let Err ( err) = nvim_open_file_remote ( nvim, & socket, file , line ) {
342366 tracing:: error!( "Failed to communicate with neovim server: {err:?}" ) ;
343367
344368 let new_port = utils:: find_free_port ( ) ;
@@ -357,7 +381,7 @@ fn run_netsock(launcher: Launcher, nvim: &str, root_dir: &Path, remote_cmd: &str
357381}
358382
359383pub fn run (
360- plugin_config : PluginConfig ,
384+ plugin_config : & PluginConfig ,
361385 root_dir : PathBuf ,
362386 file : & Path ,
363387 line : Option < usize > ,
@@ -367,7 +391,7 @@ pub fn run(
367391 . context ( "could not convert nvim path to string" ) ?
368392 . to_string ( ) ;
369393
370- let launcher = create_launcher ( & plugin_config, & nvim) ?;
394+ let launcher = create_launcher ( plugin_config, & nvim) ?;
371395
372396 let launcher = if cfg ! ( target_os = "linux" ) {
373397 launcher. apply_var (
@@ -390,21 +414,22 @@ pub fn run(
390414
391415 let file_str = file. to_str ( ) . context ( "could not convert path to string" ) ?;
392416
393- let remote_cmd = match line {
394- Some ( line) => format ! ( "+{line} {file_str}" ) ,
395- None => file_str. to_string ( ) ,
417+ let launcher = if let Some ( line) = line {
418+ launcher. apply_var ( VAR_LINE , & format ! ( "+{line}" ) )
419+ } else {
420+ launcher
396421 } ;
397422
398- let launcher = launcher. apply_var ( VAR_REMOTE_CMD , & remote_cmd . clone ( ) ) ;
423+ let launcher = launcher. apply_var ( VAR_FILE , file_str ) ;
399424
400425 match plugin_config. socket_type {
401- Some ( SocketType :: Fsock ) => run_fsock ( launcher, & nvim, & root_dir, & remote_cmd ) ?,
402- Some ( SocketType :: Netsock ) => run_netsock ( launcher, & nvim, & root_dir, & remote_cmd ) ?,
426+ Some ( SocketType :: Fsock ) => run_fsock ( launcher, & nvim, & root_dir, file_str , line ) ?,
427+ Some ( SocketType :: Netsock ) => run_netsock ( launcher, & nvim, & root_dir, file_str , line ) ?,
403428 None => {
404429 if cfg ! ( target_os = "linux" ) || cfg ! ( target_os = "macos" ) {
405- run_fsock ( launcher, & nvim, & root_dir, & remote_cmd ) ?;
430+ run_fsock ( launcher, & nvim, & root_dir, file_str , line ) ?;
406431 } else {
407- run_netsock ( launcher, & nvim, & root_dir, & remote_cmd ) ?;
432+ run_netsock ( launcher, & nvim, & root_dir, file_str , line ) ?;
408433 }
409434 }
410435 }
0 commit comments