1+ use crate :: {
2+ neovide,
3+ plugin_config:: { LauncherType , PluginConfig , SocketType } ,
4+ utils:: is_port_in_use,
5+ } ;
6+ use anyhow:: { Context , Result , bail} ;
7+ use defold_nvim_core:: { focus:: focus_neovim, nvim_server, utils:: classname} ;
18use std:: {
29 fs:: { self } ,
310 path:: { Path , PathBuf } ,
411 process:: { Child , Command } ,
512} ;
6-
7- use anyhow:: { Context , Result , bail} ;
8- use defold_nvim_core:: { focus:: focus_neovim, utils:: classname} ;
913use termlauncher:: { Application , CustomTerminal , Terminal } ;
1014use which:: which;
1115
12- use crate :: {
13- neovide,
14- plugin_config:: { LauncherType , PluginConfig , SocketType } ,
15- utils:: { self , is_port_in_use} ,
16- } ;
17-
1816const ERR_NEOVIDE_NOT_FOUND : & str = "Could not find Neovide, have you installed it?" ;
1917const ERR_TERMINAL_NOT_FOUND : & str = "Could not find any suitable terminal" ;
2018
@@ -190,12 +188,7 @@ fn run_fsock(
190188 file : & str ,
191189 line : Option < usize > ,
192190) -> Result < ( ) > {
193- let socket_file = utils:: runtime_dir (
194- root_dir
195- . to_str ( )
196- . context ( "could not convert path to string" ) ?,
197- ) ?
198- . join ( "neovim.sock" ) ;
191+ let socket_file = nvim_server:: fsock_path ( root_dir) ?;
199192
200193 tracing:: debug!( "Using fsock at {socket_file:?}" ) ;
201194
@@ -241,18 +234,8 @@ fn run_netsock(
241234 file : & str ,
242235 line : Option < usize > ,
243236) -> Result < ( ) > {
244- let port_file = utils:: runtime_dir (
245- root_dir
246- . to_str ( )
247- . context ( "could not convert path to string" ) ?,
248- ) ?
249- . join ( "port" ) ;
250-
251- let port: u16 = if port_file. exists ( ) {
252- fs:: read_to_string ( & port_file) ?. parse ( ) ?
253- } else {
254- utils:: find_free_port ( )
255- } ;
237+ let port_file = nvim_server:: netsock_port_file ( root_dir) ?;
238+ let port = nvim_server:: read_or_allocate_netsock_port ( root_dir) ?;
256239
257240 let socket = format ! ( "127.0.0.1:{port}" ) ;
258241
@@ -264,10 +247,8 @@ fn run_netsock(
264247 if let Err ( err) = nvim_open_file_remote ( nvim, & socket, file, line) {
265248 tracing:: error!( "Failed to communicate with neovim server: {err:?}" ) ;
266249
267- let new_port = utils:: find_free_port ( ) ;
268- let socket = format ! ( "127.0.0.1:{new_port}" ) ;
250+ let socket = nvim_server:: allocate_new_netsock_addr ( root_dir) ?;
269251 tracing:: debug!( "Trying to use netsock with port {socket}" ) ;
270- fs:: write ( port_file, new_port. to_string ( ) ) ?;
271252
272253 app. args = apply_vars ( & app. args , VAR_ADDRESS , & socket) ;
273254 report_process_errors ( app. launch_with ( launcher) ?) ?;
0 commit comments