@@ -11,6 +11,7 @@ use vfs::{file_set::FileSetConfig, AbsPath};
1111use crate :: {
1212 config:: { Config , FilesWatcher , LinkedProject } ,
1313 global_state:: { GlobalState , Handle } ,
14+ main_loop:: Task ,
1415} ;
1516
1617impl GlobalState {
@@ -20,51 +21,51 @@ impl GlobalState {
2021 self . analysis_host . update_lru_capacity ( old_config. lru_capacity ) ;
2122 }
2223 if self . config . linked_projects != old_config. linked_projects {
23- self . reload ( )
24+ self . fetch_workspaces ( )
2425 } else if self . config . flycheck != old_config. flycheck {
2526 self . reload_flycheck ( ) ;
2627 }
2728 }
28- pub ( crate ) fn reload ( & mut self ) {
29- log:: info!( "reloading projects: {:?}" , self . config. linked_projects) ;
30- if self . config . linked_projects . is_empty ( ) && self . config . notifications . cargo_toml_not_found
31- {
32- self . show_message (
33- lsp_types:: MessageType :: Error ,
34- "rust-analyzer failed to discover workspace" . to_string ( ) ,
35- ) ;
36- } ;
37-
38- let workspaces = {
39- self . config
40- . linked_projects
41- . iter ( )
42- . map ( |project| match project {
43- LinkedProject :: ProjectManifest ( manifest) => {
44- ra_project_model:: ProjectWorkspace :: load (
45- manifest. clone ( ) ,
46- & self . config . cargo ,
47- self . config . with_sysroot ,
48- )
49- }
50- LinkedProject :: InlineJsonProject ( it) => {
51- Ok ( ra_project_model:: ProjectWorkspace :: Json { project : it. clone ( ) } )
52- }
53- } )
54- . collect :: < Vec < _ > > ( )
55- . into_iter ( )
56- . filter_map ( |res| {
57- res. map_err ( |err| {
58- log:: error!( "failed to load workspace: {:#}" , err) ;
59- self . show_message (
60- lsp_types:: MessageType :: Error ,
61- format ! ( "rust-analyzer failed to load workspace: {:#}" , err) ,
62- ) ;
29+ pub ( crate ) fn fetch_workspaces ( & mut self ) {
30+ self . task_pool . handle . spawn ( {
31+ let linked_projects = self . config . linked_projects . clone ( ) ;
32+ let cargo_config = self . config . cargo . clone ( ) ;
33+ let with_sysroot = self . config . with_sysroot . clone ( ) ;
34+ move || {
35+ let workspaces = linked_projects
36+ . iter ( )
37+ . map ( |project| match project {
38+ LinkedProject :: ProjectManifest ( manifest) => {
39+ ra_project_model:: ProjectWorkspace :: load (
40+ manifest. clone ( ) ,
41+ & cargo_config,
42+ with_sysroot,
43+ )
44+ }
45+ LinkedProject :: InlineJsonProject ( it) => {
46+ Ok ( ra_project_model:: ProjectWorkspace :: Json { project : it. clone ( ) } )
47+ }
6348 } )
64- . ok ( )
49+ . collect :: < Vec < _ > > ( ) ;
50+ Task :: Workspaces ( workspaces)
51+ }
52+ } ) ;
53+ }
54+ pub ( crate ) fn switch_workspaces ( & mut self , workspaces : Vec < anyhow:: Result < ProjectWorkspace > > ) {
55+ log:: info!( "reloading projects: {:?}" , self . config. linked_projects) ;
56+ let workspaces = workspaces
57+ . into_iter ( )
58+ . filter_map ( |res| {
59+ res. map_err ( |err| {
60+ log:: error!( "failed to load workspace: {:#}" , err) ;
61+ self . show_message (
62+ lsp_types:: MessageType :: Error ,
63+ format ! ( "rust-analyzer failed to load workspace: {:#}" , err) ,
64+ ) ;
6565 } )
66- . collect :: < Vec < _ > > ( )
67- } ;
66+ . ok ( )
67+ } )
68+ . collect :: < Vec < _ > > ( ) ;
6869
6970 if let FilesWatcher :: Client = self . config . files . watcher {
7071 let registration_options = lsp_types:: DidChangeWatchedFilesRegistrationOptions {
0 commit comments