aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-05-23 21:29:26 +0100
committerKirill Bulatov <[email protected]>2021-05-23 21:37:59 +0100
commit72594beca46ac4a05b0c54f26a285f5197192b8b (patch)
tree29d5fc842f4805a2e50c558a1289825202734aa2
parent2ca2e24a39594762be80ac11247b231c13a4b2af (diff)
Deal with todos
-rw-r--r--crates/project_model/src/workspace.rs18
1 files changed, 14 insertions, 4 deletions
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 {
49 }, 49 },
50 /// Project workspace was manually specified using a `rust-project.json` file. 50 /// Project workspace was manually specified using a `rust-project.json` file.
51 Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> }, 51 Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> },
52 /// TODO kb docs 52 /// Project with a set of disjoint files, not belonging to any particular workspace.
53 /// Backed by basic sysroot crates for basic completion and highlighting.
53 DetachedFiles { files: Vec<AbsPathBuf>, sysroot: Sysroot, rustc_cfg: Vec<CfgFlag> }, 54 DetachedFiles { files: Vec<AbsPathBuf>, sysroot: Sysroot, rustc_cfg: Vec<CfgFlag> },
54} 55}
55 56
@@ -509,7 +510,6 @@ fn cargo_to_crate_graph(
509 crate_graph 510 crate_graph
510} 511}
511 512
512// TODO kb refactor and check for correctness
513fn detached_files_to_crate_graph( 513fn detached_files_to_crate_graph(
514 rustc_cfg: Vec<CfgFlag>, 514 rustc_cfg: Vec<CfgFlag>,
515 load: &mut dyn FnMut(&AbsPath) -> Option<FileId>, 515 load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
@@ -525,11 +525,21 @@ fn detached_files_to_crate_graph(
525 cfg_options.extend(rustc_cfg); 525 cfg_options.extend(rustc_cfg);
526 526
527 for detached_file in detached_files { 527 for detached_file in detached_files {
528 let file_id = load(&detached_file).unwrap(); 528 let file_id = match load(&detached_file) {
529 Some(file_id) => file_id,
530 None => {
531 log::error!("Failed to load detached file {:?}", detached_file);
532 continue;
533 }
534 };
535 let display_name = detached_file
536 .file_stem()
537 .and_then(|os_str| os_str.to_str())
538 .map(|file_stem| CrateDisplayName::from_canonical_name(file_stem.to_string()));
529 let detached_file_crate = crate_graph.add_crate_root( 539 let detached_file_crate = crate_graph.add_crate_root(
530 file_id, 540 file_id,
531 Edition::Edition2018, 541 Edition::Edition2018,
532 None, 542 display_name,
533 cfg_options.clone(), 543 cfg_options.clone(),
534 Env::default(), 544 Env::default(),
535 Vec::new(), 545 Vec::new(),