diff options
Diffstat (limited to 'crates/rust-analyzer/src/reload.rs')
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 9fc56349c..74c3344df 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -11,6 +11,7 @@ use vfs::{file_set::FileSetConfig, AbsPath}; | |||
11 | use crate::{ | 11 | use crate::{ |
12 | config::{Config, FilesWatcher, LinkedProject}, | 12 | config::{Config, FilesWatcher, LinkedProject}, |
13 | global_state::{GlobalState, Handle}, | 13 | global_state::{GlobalState, Handle}, |
14 | main_loop::Task, | ||
14 | }; | 15 | }; |
15 | 16 | ||
16 | impl GlobalState { | 17 | impl GlobalState { |
@@ -20,51 +21,51 @@ impl GlobalState { | |||
20 | self.analysis_host.update_lru_capacity(old_config.lru_capacity); | 21 | self.analysis_host.update_lru_capacity(old_config.lru_capacity); |
21 | } | 22 | } |
22 | if self.config.linked_projects != old_config.linked_projects { | 23 | if self.config.linked_projects != old_config.linked_projects { |
23 | self.reload() | 24 | self.fetch_workspaces() |
24 | } else if self.config.flycheck != old_config.flycheck { | 25 | } else if self.config.flycheck != old_config.flycheck { |
25 | self.reload_flycheck(); | 26 | self.reload_flycheck(); |
26 | } | 27 | } |
27 | } | 28 | } |
28 | pub(crate) fn reload(&mut self) { | 29 | pub(crate) fn fetch_workspaces(&mut self) { |
29 | log::info!("reloading projects: {:?}", self.config.linked_projects); | 30 | self.task_pool.handle.spawn({ |
30 | if self.config.linked_projects.is_empty() && self.config.notifications.cargo_toml_not_found | 31 | let linked_projects = self.config.linked_projects.clone(); |
31 | { | 32 | let cargo_config = self.config.cargo.clone(); |
32 | self.show_message( | 33 | let with_sysroot = self.config.with_sysroot.clone(); |
33 | lsp_types::MessageType::Error, | 34 | move || { |
34 | "rust-analyzer failed to discover workspace".to_string(), | 35 | let workspaces = linked_projects |
35 | ); | 36 | .iter() |
36 | }; | 37 | .map(|project| match project { |
37 | 38 | LinkedProject::ProjectManifest(manifest) => { | |
38 | let workspaces = { | 39 | ra_project_model::ProjectWorkspace::load( |
39 | self.config | 40 | manifest.clone(), |
40 | .linked_projects | 41 | &cargo_config, |
41 | .iter() | 42 | with_sysroot, |
42 | .map(|project| match project { | 43 | ) |
43 | LinkedProject::ProjectManifest(manifest) => { | 44 | } |
44 | ra_project_model::ProjectWorkspace::load( | 45 | LinkedProject::InlineJsonProject(it) => { |
45 | manifest.clone(), | 46 | Ok(ra_project_model::ProjectWorkspace::Json { project: it.clone() }) |
46 | &self.config.cargo, | 47 | } |
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 | ); | ||
63 | }) | 48 | }) |
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 | ); | ||
65 | }) | 65 | }) |
66 | .collect::<Vec<_>>() | 66 | .ok() |
67 | }; | 67 | }) |
68 | .collect::<Vec<_>>(); | ||
68 | 69 | ||
69 | if let FilesWatcher::Client = self.config.files.watcher { | 70 | if let FilesWatcher::Client = self.config.files.watcher { |
70 | let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions { | 71 | let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions { |