diff options
author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-04-16 21:02:10 +0100 |
---|---|---|
committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-04-16 21:02:10 +0100 |
commit | be2654b0ed3e4eb51bc3745b2329d6264588549f (patch) | |
tree | 6340818f6ddf3b13360f09431c6208cc98786a21 /crates/rust-analyzer/src/main_loop.rs | |
parent | cae2498513601c507bb10b15710feb800a24517f (diff) |
Decouple project loading from project discovery a bit
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 8d1429196..9c345601c 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -88,37 +88,49 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection) | |||
88 | 88 | ||
89 | let mut loop_state = LoopState::default(); | 89 | let mut loop_state = LoopState::default(); |
90 | let mut world_state = { | 90 | let mut world_state = { |
91 | // FIXME: support dynamic workspace loading. | ||
92 | let workspaces = { | 91 | let workspaces = { |
93 | let mut loaded_workspaces = Vec::new(); | 92 | // FIXME: support dynamic workspace loading. |
94 | for ws_root in &ws_roots { | 93 | let mut visited = FxHashSet::default(); |
95 | let workspace = ra_project_model::ProjectWorkspace::discover_with_sysroot( | 94 | let project_roots = ws_roots |
96 | ws_root.as_path(), | 95 | .iter() |
97 | config.with_sysroot, | 96 | .map(|it| ra_project_model::ProjectRoot::discover(it)) |
98 | &config.cargo, | 97 | .filter_map(|dir| { |
99 | ); | 98 | dir.map_err(|cargo_toml_not_found| { |
100 | match workspace { | 99 | log::error!("discovering workspace failed: {:?}", cargo_toml_not_found); |
101 | Ok(workspace) => loaded_workspaces.push(workspace), | 100 | |
102 | Err(e) => { | 101 | if config.notifications.cargo_toml_not_found { |
103 | log::error!("loading workspace failed: {:?}", e); | 102 | show_message( |
104 | 103 | req::MessageType::Error, | |
105 | if let Some(ra_project_model::CargoTomlNotFoundError { .. }) = | 104 | format!( |
106 | e.downcast_ref() | 105 | "rust-analyzer failed to discover workspace: {:?}", |
107 | { | 106 | cargo_toml_not_found |
108 | if !config.notifications.cargo_toml_not_found { | 107 | ), |
109 | continue; | 108 | &connection.sender, |
110 | } | 109 | ); |
111 | } | 110 | } |
112 | 111 | }) | |
112 | .ok() | ||
113 | }) | ||
114 | .filter(|it| visited.insert(it.clone())); | ||
115 | |||
116 | project_roots | ||
117 | .filter_map(|root| { | ||
118 | ra_project_model::ProjectWorkspace::load( | ||
119 | root, | ||
120 | &config.cargo, | ||
121 | config.with_sysroot, | ||
122 | ) | ||
123 | .map_err(|err| { | ||
124 | log::error!("failed to load workspace: {:#}", err); | ||
113 | show_message( | 125 | show_message( |
114 | req::MessageType::Error, | 126 | req::MessageType::Error, |
115 | format!("rust-analyzer failed to load workspace: {:?}", e), | 127 | format!("rust-analyzer failed to load workspace: {:#}", err), |
116 | &connection.sender, | 128 | &connection.sender, |
117 | ); | 129 | ); |
118 | } | 130 | }) |
119 | } | 131 | .ok() |
120 | } | 132 | }) |
121 | loaded_workspaces | 133 | .collect::<Vec<_>>() |
122 | }; | 134 | }; |
123 | 135 | ||
124 | let globs = config | 136 | let globs = config |