From 72594beca46ac4a05b0c54f26a285f5197192b8b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 23 May 2021 23:29:26 +0300 Subject: Deal with todos --- crates/project_model/src/workspace.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'crates/project_model') diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index ad4c202f2..ede82d88b 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -49,7 +49,8 @@ pub enum ProjectWorkspace { }, /// Project workspace was manually specified using a `rust-project.json` file. Json { project: ProjectJson, sysroot: Option, rustc_cfg: Vec }, - /// TODO kb docs + /// Project with a set of disjoint files, not belonging to any particular workspace. + /// Backed by basic sysroot crates for basic completion and highlighting. DetachedFiles { files: Vec, sysroot: Sysroot, rustc_cfg: Vec }, } @@ -509,7 +510,6 @@ fn cargo_to_crate_graph( crate_graph } -// TODO kb refactor and check for correctness fn detached_files_to_crate_graph( rustc_cfg: Vec, load: &mut dyn FnMut(&AbsPath) -> Option, @@ -525,11 +525,21 @@ fn detached_files_to_crate_graph( cfg_options.extend(rustc_cfg); for detached_file in detached_files { - let file_id = load(&detached_file).unwrap(); + let file_id = match load(&detached_file) { + Some(file_id) => file_id, + None => { + log::error!("Failed to load detached file {:?}", detached_file); + continue; + } + }; + let display_name = detached_file + .file_stem() + .and_then(|os_str| os_str.to_str()) + .map(|file_stem| CrateDisplayName::from_canonical_name(file_stem.to_string())); let detached_file_crate = crate_graph.add_crate_root( file_id, Edition::Edition2018, - None, + display_name, cfg_options.clone(), Env::default(), Vec::new(), -- cgit v1.2.3