@ -673,10 +673,10 @@ impl Registry {
self . inner . get ( id )
self . inner . get ( id )
}
}
pub fn remove_by_id ( & mut self , id : LanguageServerId ) {
pub fn remove_by_id ( & mut self , id : LanguageServerId ) -> Option < Arc < Client > > {
let Some ( client ) = self . inner . remove ( id ) else {
let Some ( client ) = self . inner . remove ( id ) else {
log ::debug ! ( "client was already removed" ) ;
log ::error ! ( "client was already removed" ) ;
return ;
return None ;
} ;
} ;
self . file_event_handler . remove_client ( id ) ;
self . file_event_handler . remove_client ( id ) ;
let instances = self
let instances = self
@ -687,22 +687,23 @@ impl Registry {
if instances . is_empty ( ) {
if instances . is_empty ( ) {
self . inner_by_name . remove ( client . name ( ) ) ;
self . inner_by_name . remove ( client . name ( ) ) ;
}
}
Some ( client )
}
}
fn star t_clien t(
pub fn star t(
& mut self ,
& mut self ,
name : String ,
name : String ,
ls_config : & LanguageConfiguration ,
ls_config : & LanguageConfiguration ,
doc_path : Option < & std ::path ::PathBuf > ,
doc_path : Option < & std ::path ::PathBuf > ,
root_dirs : & [ PathBuf ] ,
root_dirs : & [ PathBuf ] ,
enable_snippets : bool ,
enable_snippets : bool ,
) -> Result < Arc < Client > , Startup Error> {
) -> Result < Option < Arc < Client > > , Error> {
let syn_loader = self . syn_loader . load ( ) ;
let syn_loader = self . syn_loader . load ( ) ;
let config = syn_loader
let config = syn_loader
. language_server_configs ( )
. language_server_configs ( )
. get ( & name )
. get ( & name )
. ok_or_else ( | | anyhow ::anyhow ! ( "Language server '{name}' not defined" ) ) ? ;
. ok_or_else ( | | anyhow ::anyhow ! ( "Language server '{name}' not defined" ) ) ? ;
let id = self . inner . try_insert_with_key ( | id | {
match self . inner . try_insert_with_key ( | id | {
start_client (
start_client (
id ,
id ,
name ,
name ,
@ -716,8 +717,11 @@ impl Registry {
self . incoming . push ( UnboundedReceiverStream ::new ( client . 1 ) ) ;
self . incoming . push ( UnboundedReceiverStream ::new ( client . 1 ) ) ;
client . 0
client . 0
} )
} )
} ) ? ;
} ) {
Ok ( self . inner [ id ] . clone ( ) )
Ok ( id ) = > Ok ( Some ( self . inner [ id ] . clone ( ) ) ) ,
Err ( StartupError ::NoRequiredRootFound ) = > Ok ( None ) ,
Err ( StartupError ::Error ( err ) ) = > Err ( err ) ,
}
}
}
/// If this method is called, all documents that have a reference to language servers used by the language config have to refresh their language servers,
/// If this method is called, all documents that have a reference to language servers used by the language config have to refresh their language servers,
@ -748,16 +752,18 @@ impl Registry {
} ) ;
} ) ;
}
}
}
}
let client = match self . start_client (
let client = match self
. start (
name . clone ( ) ,
name . clone ( ) ,
language_config ,
language_config ,
doc_path ,
doc_path ,
root_dirs ,
root_dirs ,
enable_snippets ,
enable_snippets ,
) {
)
. transpose ( ) ?
{
Ok ( client ) = > client ,
Ok ( client ) = > client ,
Err ( StartupError ::NoRequiredRootFound ) = > return None ,
Err ( err ) = > return Some ( Err ( err ) ) ,
Err ( StartupError ::Error ( err ) ) = > return Some ( Err ( err ) ) ,
} ;
} ;
self . inner_by_name
self . inner_by_name
. insert ( name . to_owned ( ) , vec! [ client . clone ( ) ] ) ;
. insert ( name . to_owned ( ) , vec! [ client . clone ( ) ] ) ;
@ -808,23 +814,22 @@ impl Registry {
return Some ( ( name . to_owned ( ) , Ok ( client . clone ( ) ) ) ) ;
return Some ( ( name . to_owned ( ) , Ok ( client . clone ( ) ) ) ) ;
}
}
}
}
match self . start_client (
let client = self
. start (
name . clone ( ) ,
name . clone ( ) ,
language_config ,
language_config ,
doc_path ,
doc_path ,
root_dirs ,
root_dirs ,
enable_snippets ,
enable_snippets ,
) {
)
Ok ( client ) = > {
. transpose ( ) ? ;
if let Ok ( client ) = & client {
self . inner_by_name
self . inner_by_name
. entry ( name . to_owned ( ) )
. entry ( name . to_owned ( ) )
. or_default ( )
. or_default ( )
. push ( client . clone ( ) ) ;
. push ( client . clone ( ) ) ;
Some ( ( name . clone ( ) , Ok ( client ) ) )
}
Err ( StartupError ::NoRequiredRootFound ) = > None ,
Err ( StartupError ::Error ( err ) ) = > Some ( ( name . to_owned ( ) , Err ( err ) ) ) ,
}
}
Some ( ( name . to_owned ( ) , client ) )
} ,
} ,
)
)
}
}