Decouple project loading from project discovery a bit
This commit is contained in:
@@ -88,37 +88,49 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
|
||||
|
||||
let mut loop_state = LoopState::default();
|
||||
let mut world_state = {
|
||||
// FIXME: support dynamic workspace loading.
|
||||
let workspaces = {
|
||||
let mut loaded_workspaces = Vec::new();
|
||||
for ws_root in &ws_roots {
|
||||
let workspace = ra_project_model::ProjectWorkspace::discover_with_sysroot(
|
||||
ws_root.as_path(),
|
||||
config.with_sysroot,
|
||||
&config.cargo,
|
||||
);
|
||||
match workspace {
|
||||
Ok(workspace) => loaded_workspaces.push(workspace),
|
||||
Err(e) => {
|
||||
log::error!("loading workspace failed: {:?}", e);
|
||||
// FIXME: support dynamic workspace loading.
|
||||
let mut visited = FxHashSet::default();
|
||||
let project_roots = ws_roots
|
||||
.iter()
|
||||
.map(|it| ra_project_model::ProjectRoot::discover(it))
|
||||
.filter_map(|dir| {
|
||||
dir.map_err(|cargo_toml_not_found| {
|
||||
log::error!("discovering workspace failed: {:?}", cargo_toml_not_found);
|
||||
|
||||
if let Some(ra_project_model::CargoTomlNotFoundError { .. }) =
|
||||
e.downcast_ref()
|
||||
{
|
||||
if !config.notifications.cargo_toml_not_found {
|
||||
continue;
|
||||
}
|
||||
if config.notifications.cargo_toml_not_found {
|
||||
show_message(
|
||||
req::MessageType::Error,
|
||||
format!(
|
||||
"rust-analyzer failed to discover workspace: {:?}",
|
||||
cargo_toml_not_found
|
||||
),
|
||||
&connection.sender,
|
||||
);
|
||||
}
|
||||
})
|
||||
.ok()
|
||||
})
|
||||
.filter(|it| visited.insert(it.clone()));
|
||||
|
||||
project_roots
|
||||
.filter_map(|root| {
|
||||
ra_project_model::ProjectWorkspace::load(
|
||||
root,
|
||||
&config.cargo,
|
||||
config.with_sysroot,
|
||||
)
|
||||
.map_err(|err| {
|
||||
log::error!("failed to load workspace: {:#}", err);
|
||||
show_message(
|
||||
req::MessageType::Error,
|
||||
format!("rust-analyzer failed to load workspace: {:?}", e),
|
||||
format!("rust-analyzer failed to load workspace: {:#}", err),
|
||||
&connection.sender,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
loaded_workspaces
|
||||
})
|
||||
.ok()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
let globs = config
|
||||
|
||||
Reference in New Issue
Block a user