aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_db/src/fixture.rs11
-rw-r--r--crates/ra_db/src/input.rs99
-rw-r--r--crates/ra_ide/src/hover.rs43
-rw-r--r--crates/ra_ide/src/lib.rs8
-rw-r--r--crates/ra_ide/src/mock_analysis.rs10
-rw-r--r--crates/ra_ide/src/parent_module.rs1
-rw-r--r--crates/ra_ide_db/src/change.rs6
-rw-r--r--crates/ra_ide_db/src/lib.rs6
-rw-r--r--crates/ra_project_model/src/lib.rs13
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs11
-rw-r--r--crates/rust-analyzer/src/world.rs13
11 files changed, 135 insertions, 86 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index da7af110c..947d6ad56 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -56,6 +56,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, text: &str) -> FileId {
56 crate_graph.add_crate_root( 56 crate_graph.add_crate_root(
57 file_id, 57 file_id,
58 Edition::Edition2018, 58 Edition::Edition2018,
59 None,
59 CfgOptions::default(), 60 CfgOptions::default(),
60 Env::default(), 61 Env::default(),
61 ); 62 );
@@ -98,8 +99,13 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
98 assert!(meta.path.starts_with(&source_root_prefix)); 99 assert!(meta.path.starts_with(&source_root_prefix));
99 100
100 if let Some(krate) = meta.krate { 101 if let Some(krate) = meta.krate {
101 let crate_id = 102 let crate_id = crate_graph.add_crate_root(
102 crate_graph.add_crate_root(file_id, meta.edition, meta.cfg, Env::default()); 103 file_id,
104 meta.edition,
105 Some(krate.clone()),
106 meta.cfg,
107 Env::default(),
108 );
103 let prev = crates.insert(krate.clone(), crate_id); 109 let prev = crates.insert(krate.clone(), crate_id);
104 assert!(prev.is_none()); 110 assert!(prev.is_none());
105 for dep in meta.deps { 111 for dep in meta.deps {
@@ -132,6 +138,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
132 crate_graph.add_crate_root( 138 crate_graph.add_crate_root(
133 crate_root, 139 crate_root,
134 Edition::Edition2018, 140 Edition::Edition2018,
141 None,
135 CfgOptions::default(), 142 CfgOptions::default(),
136 Env::default(), 143 Env::default(),
137 ); 144 );
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index eaff99fd3..7b9f4efe4 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -86,7 +86,7 @@ pub struct CrateId(pub u32);
86pub struct CrateName(SmolStr); 86pub struct CrateName(SmolStr);
87 87
88impl CrateName { 88impl CrateName {
89 /// Crates a crate name, checking for dashes in the string provided. 89 /// Creates a crate name, checking for dashes in the string provided.
90 /// Dashes are not allowed in the crate names, 90 /// Dashes are not allowed in the crate names,
91 /// hence the input string is returned as `Err` for those cases. 91 /// hence the input string is returned as `Err` for those cases.
92 pub fn new(name: &str) -> Result<CrateName, &str> { 92 pub fn new(name: &str) -> Result<CrateName, &str> {
@@ -97,7 +97,7 @@ impl CrateName {
97 } 97 }
98 } 98 }
99 99
100 /// Crates a crate name, unconditionally replacing the dashes with underscores. 100 /// Creates a crate name, unconditionally replacing the dashes with underscores.
101 pub fn normalize_dashes(name: &str) -> CrateName { 101 pub fn normalize_dashes(name: &str) -> CrateName {
102 Self(SmolStr::new(name.replace('-', "_"))) 102 Self(SmolStr::new(name.replace('-', "_")))
103 } 103 }
@@ -107,6 +107,7 @@ impl CrateName {
107struct CrateData { 107struct CrateData {
108 file_id: FileId, 108 file_id: FileId,
109 edition: Edition, 109 edition: Edition,
110 declaration_name: Option<String>,
110 cfg_options: CfgOptions, 111 cfg_options: CfgOptions,
111 env: Env, 112 env: Env,
112 dependencies: Vec<Dependency>, 113 dependencies: Vec<Dependency>,
@@ -134,10 +135,11 @@ impl CrateGraph {
134 &mut self, 135 &mut self,
135 file_id: FileId, 136 file_id: FileId,
136 edition: Edition, 137 edition: Edition,
138 declaration_name: Option<String>,
137 cfg_options: CfgOptions, 139 cfg_options: CfgOptions,
138 env: Env, 140 env: Env,
139 ) -> CrateId { 141 ) -> CrateId {
140 let data = CrateData::new(file_id, edition, cfg_options, env); 142 let data = CrateData::new(file_id, edition, declaration_name, cfg_options, env);
141 let crate_id = CrateId(self.arena.len() as u32); 143 let crate_id = CrateId(self.arena.len() as u32);
142 let prev = self.arena.insert(crate_id, data); 144 let prev = self.arena.insert(crate_id, data);
143 assert!(prev.is_none()); 145 assert!(prev.is_none());
@@ -177,6 +179,15 @@ impl CrateGraph {
177 self.arena[&crate_id].edition 179 self.arena[&crate_id].edition
178 } 180 }
179 181
182 /// Returns a name of a crate, declared in the root project.
183 /// May be missing for some cases, such as when the crate definition was created for a code snippet.
184 ///
185 /// This should not be considered as a normal crate name, since the actual name can be different in
186 /// a particular dependent crate, where it is specified.
187 pub fn declaration_name(&self, crate_id: &CrateId) -> Option<&String> {
188 self.arena[crate_id].declaration_name.as_ref()
189 }
190
180 // FIXME: this only finds one crate with the given root; we could have multiple 191 // FIXME: this only finds one crate with the given root; we could have multiple
181 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> { 192 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
182 let (&crate_id, _) = self.arena.iter().find(|(_crate_id, data)| data.file_id == file_id)?; 193 let (&crate_id, _) = self.arena.iter().find(|(_crate_id, data)| data.file_id == file_id)?;
@@ -230,8 +241,14 @@ impl CrateId {
230} 241}
231 242
232impl CrateData { 243impl CrateData {
233 fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions, env: Env) -> CrateData { 244 fn new(
234 CrateData { file_id, edition, dependencies: Vec::new(), cfg_options, env } 245 file_id: FileId,
246 edition: Edition,
247 declaration_name: Option<String>,
248 cfg_options: CfgOptions,
249 env: Env,
250 ) -> CrateData {
251 CrateData { file_id, edition, declaration_name, dependencies: Vec::new(), cfg_options, env }
235 } 252 }
236 253
237 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { 254 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
@@ -290,12 +307,27 @@ mod tests {
290 #[test] 307 #[test]
291 fn it_should_panic_because_of_cycle_dependencies() { 308 fn it_should_panic_because_of_cycle_dependencies() {
292 let mut graph = CrateGraph::default(); 309 let mut graph = CrateGraph::default();
293 let crate1 = 310 let crate1 = graph.add_crate_root(
294 graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default(), Env::default()); 311 FileId(1u32),
295 let crate2 = 312 Edition2018,
296 graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default(), Env::default()); 313 None,
297 let crate3 = 314 CfgOptions::default(),
298 graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default(), Env::default()); 315 Env::default(),
316 );
317 let crate2 = graph.add_crate_root(
318 FileId(2u32),
319 Edition2018,
320 None,
321 CfgOptions::default(),
322 Env::default(),
323 );
324 let crate3 = graph.add_crate_root(
325 FileId(3u32),
326 Edition2018,
327 None,
328 CfgOptions::default(),
329 Env::default(),
330 );
299 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 331 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
300 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 332 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
301 assert!(graph.add_dep(crate3, CrateName::new("crate1").unwrap(), crate1).is_err()); 333 assert!(graph.add_dep(crate3, CrateName::new("crate1").unwrap(), crate1).is_err());
@@ -304,12 +336,27 @@ mod tests {
304 #[test] 336 #[test]
305 fn it_works() { 337 fn it_works() {
306 let mut graph = CrateGraph::default(); 338 let mut graph = CrateGraph::default();
307 let crate1 = 339 let crate1 = graph.add_crate_root(
308 graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default(), Env::default()); 340 FileId(1u32),
309 let crate2 = 341 Edition2018,
310 graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default(), Env::default()); 342 None,
311 let crate3 = 343 CfgOptions::default(),
312 graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default(), Env::default()); 344 Env::default(),
345 );
346 let crate2 = graph.add_crate_root(
347 FileId(2u32),
348 Edition2018,
349 None,
350 CfgOptions::default(),
351 Env::default(),
352 );
353 let crate3 = graph.add_crate_root(
354 FileId(3u32),
355 Edition2018,
356 None,
357 CfgOptions::default(),
358 Env::default(),
359 );
313 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 360 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
314 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 361 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
315 } 362 }
@@ -317,10 +364,20 @@ mod tests {
317 #[test] 364 #[test]
318 fn dashes_are_normalized() { 365 fn dashes_are_normalized() {
319 let mut graph = CrateGraph::default(); 366 let mut graph = CrateGraph::default();
320 let crate1 = 367 let crate1 = graph.add_crate_root(
321 graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default(), Env::default()); 368 FileId(1u32),
322 let crate2 = 369 Edition2018,
323 graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default(), Env::default()); 370 None,
371 CfgOptions::default(),
372 Env::default(),
373 );
374 let crate2 = graph.add_crate_root(
375 FileId(2u32),
376 Edition2018,
377 None,
378 CfgOptions::default(),
379 Env::default(),
380 );
324 assert!(graph 381 assert!(graph
325 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) 382 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2)
326 .is_ok()); 383 .is_ok());
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index da3b67943..f87054838 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -1,8 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{ 3use hir::{
4 Adt, AsAssocItem, AssocItemContainer, HasSource, HirDisplay, ModuleDef, ModuleSource, Semantics, 4 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef,
5 ModuleSource, Semantics,
5}; 6};
7use ra_db::SourceDatabase;
6use ra_ide_db::{ 8use ra_ide_db::{
7 defs::{classify_name, classify_name_ref, Definition}, 9 defs::{classify_name, classify_name_ref, Definition},
8 RootDatabase, 10 RootDatabase,
@@ -119,7 +121,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
119 121
120fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { 122fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
121 let mod_path = def.module(db).map(|module| { 123 let mod_path = def.module(db).map(|module| {
122 once(db.get_crate_original_name(&module.krate().into())) 124 once(db.crate_graph().declaration_name(&module.krate().into()).cloned())
123 .chain( 125 .chain(
124 module 126 module
125 .path_to_root(db) 127 .path_to_root(db)
@@ -144,7 +146,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option<Strin
144 Definition::StructField(it) => { 146 Definition::StructField(it) => {
145 let src = it.source(db); 147 let src = it.source(db);
146 match src.value { 148 match src.value {
147 hir::FieldSource::Named(it) => { 149 FieldSource::Named(it) => {
148 hover_text(it.doc_comment_text(), it.short_label(), mod_path) 150 hover_text(it.doc_comment_text(), it.short_label(), mod_path)
149 } 151 }
150 _ => None, 152 _ => None,
@@ -576,21 +578,23 @@ fn func(foo: i32) { if true { <|>foo; }; }
576 fn test_hover_infer_associated_method_exact() { 578 fn test_hover_infer_associated_method_exact() {
577 let (analysis, position) = single_file_with_position( 579 let (analysis, position) = single_file_with_position(
578 " 580 "
579 struct Thing { x: u32 } 581 mod wrapper {
582 struct Thing { x: u32 }
580 583
581 impl Thing { 584 impl Thing {
582 fn new() -> Thing { 585 fn new() -> Thing {
583 Thing { x: 0 } 586 Thing { x: 0 }
587 }
584 } 588 }
585 } 589 }
586 590
587 fn main() { 591 fn main() {
588 let foo_test = Thing::new<|>(); 592 let foo_test = wrapper::Thing::new<|>();
589 } 593 }
590 ", 594 ",
591 ); 595 );
592 let hover = analysis.hover(position).unwrap().unwrap(); 596 let hover = analysis.hover(position).unwrap().unwrap();
593 assert_eq!(trim_markup_opt(hover.info.first()), Some("fn new() -> Thing")); 597 assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing"));
594 assert_eq!(hover.info.is_exact(), true); 598 assert_eq!(hover.info.is_exact(), true);
595 } 599 }
596 600
@@ -863,25 +867,4 @@ fn func(foo: i32) { if true { <|>foo; }; }
863 &["fn foo()\n```\n\n<- `\u{3000}` here"], 867 &["fn foo()\n```\n\n<- `\u{3000}` here"],
864 ); 868 );
865 } 869 }
866
867 #[test]
868 fn zzz() {
869 check_hover_result(
870 "
871 //- /main.rs
872 mod vvv {
873 pub struct Test;
874
875 impl Test {
876 pub fn whatever() {}
877 }
878 }
879
880 fn main() {
881 vvv::Test::what<|>ever();
882 }
883 ",
884 &["vvv::Test\npub fn whatever()"],
885 );
886 }
887} 870}
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 4dfe0553e..56bc57d5c 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -211,7 +211,13 @@ impl Analysis {
211 // Default to enable test for single file. 211 // Default to enable test for single file.
212 let mut cfg_options = CfgOptions::default(); 212 let mut cfg_options = CfgOptions::default();
213 cfg_options.insert_atom("test".into()); 213 cfg_options.insert_atom("test".into());
214 crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options, Env::default()); 214 crate_graph.add_crate_root(
215 file_id,
216 Edition::Edition2018,
217 None,
218 cfg_options,
219 Env::default(),
220 );
215 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); 221 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text));
216 change.set_crate_graph(crate_graph); 222 change.set_crate_graph(crate_graph);
217 host.apply_change(change); 223 host.apply_change(change);
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index f4cd6deb7..90f84b052 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -99,13 +99,19 @@ impl MockAnalysis {
99 root_crate = Some(crate_graph.add_crate_root( 99 root_crate = Some(crate_graph.add_crate_root(
100 file_id, 100 file_id,
101 Edition2018, 101 Edition2018,
102 None,
102 cfg_options, 103 cfg_options,
103 Env::default(), 104 Env::default(),
104 )); 105 ));
105 } else if path.ends_with("/lib.rs") { 106 } else if path.ends_with("/lib.rs") {
106 let other_crate =
107 crate_graph.add_crate_root(file_id, Edition2018, cfg_options, Env::default());
108 let crate_name = path.parent().unwrap().file_name().unwrap(); 107 let crate_name = path.parent().unwrap().file_name().unwrap();
108 let other_crate = crate_graph.add_crate_root(
109 file_id,
110 Edition2018,
111 Some(crate_name.to_owned()),
112 cfg_options,
113 Env::default(),
114 );
109 if let Some(root_crate) = root_crate { 115 if let Some(root_crate) = root_crate {
110 crate_graph 116 crate_graph
111 .add_dep(root_crate, CrateName::new(crate_name).unwrap(), other_crate) 117 .add_dep(root_crate, CrateName::new(crate_name).unwrap(), other_crate)
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs
index 2c4bdb039..b73cefd97 100644
--- a/crates/ra_ide/src/parent_module.rs
+++ b/crates/ra_ide/src/parent_module.rs
@@ -133,6 +133,7 @@ mod tests {
133 let crate_id = crate_graph.add_crate_root( 133 let crate_id = crate_graph.add_crate_root(
134 root_file, 134 root_file,
135 Edition2018, 135 Edition2018,
136 None,
136 CfgOptions::default(), 137 CfgOptions::default(),
137 Env::default(), 138 Env::default(),
138 ); 139 );
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index 8b5be9d21..628cf6416 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -5,7 +5,7 @@ use std::{fmt, sync::Arc, time};
5 5
6use ra_db::{ 6use ra_db::{
7 salsa::{Database, Durability, SweepStrategy}, 7 salsa::{Database, Durability, SweepStrategy},
8 CrateGraph, CrateId, FileId, RelativePathBuf, SourceDatabase, SourceDatabaseExt, SourceRoot, 8 CrateGraph, FileId, RelativePathBuf, SourceDatabase, SourceDatabaseExt, SourceRoot,
9 SourceRootId, 9 SourceRootId,
10}; 10};
11use ra_prof::{memory_usage, profile, Bytes}; 11use ra_prof::{memory_usage, profile, Bytes};
@@ -88,10 +88,6 @@ impl AnalysisChange {
88 self.crate_graph = Some(graph); 88 self.crate_graph = Some(graph);
89 } 89 }
90 90
91 pub fn set_debug_crate_name(&mut self, crate_id: CrateId, name: String) {
92 self.debug_data.crate_names.insert(crate_id, name);
93 }
94
95 pub fn set_debug_root_path(&mut self, source_root_id: SourceRootId, path: String) { 91 pub fn set_debug_root_path(&mut self, source_root_id: SourceRootId, path: String) {
96 self.debug_data.root_paths.insert(source_root_id, path); 92 self.debug_data.root_paths.insert(source_root_id, path);
97 } 93 }
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs
index efa472c7d..a105c7556 100644
--- a/crates/ra_ide_db/src/lib.rs
+++ b/crates/ra_ide_db/src/lib.rs
@@ -104,10 +104,6 @@ impl RootDatabase {
104 db.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); 104 db.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity);
105 db 105 db
106 } 106 }
107
108 pub fn get_crate_original_name(&self, crate_id: &CrateId) -> Option<String> {
109 self.debug_data.crate_names.get(crate_id).cloned()
110 }
111} 107}
112 108
113impl salsa::ParallelDatabase for RootDatabase { 109impl salsa::ParallelDatabase for RootDatabase {
@@ -135,12 +131,10 @@ fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
135#[derive(Debug, Default, Clone)] 131#[derive(Debug, Default, Clone)]
136pub(crate) struct DebugData { 132pub(crate) struct DebugData {
137 pub(crate) root_paths: FxHashMap<SourceRootId, String>, 133 pub(crate) root_paths: FxHashMap<SourceRootId, String>,
138 pub(crate) crate_names: FxHashMap<CrateId, String>,
139} 134}
140 135
141impl DebugData { 136impl DebugData {
142 pub(crate) fn merge(&mut self, other: DebugData) { 137 pub(crate) fn merge(&mut self, other: DebugData) {
143 self.root_paths.extend(other.root_paths.into_iter()); 138 self.root_paths.extend(other.root_paths.into_iter());
144 self.crate_names.extend(other.crate_names.into_iter());
145 } 139 }
146} 140}
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index bcf12460d..37845ca56 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -14,7 +14,7 @@ use std::{
14 14
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use ra_cfg::CfgOptions; 16use ra_cfg::CfgOptions;
17use ra_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId}; 17use ra_db::{CrateGraph, CrateName, Edition, Env, FileId};
18use rustc_hash::FxHashMap; 18use rustc_hash::FxHashMap;
19use serde_json::from_reader; 19use serde_json::from_reader;
20 20
@@ -163,9 +163,8 @@ impl ProjectWorkspace {
163 &self, 163 &self,
164 default_cfg_options: &CfgOptions, 164 default_cfg_options: &CfgOptions,
165 load: &mut dyn FnMut(&Path) -> Option<FileId>, 165 load: &mut dyn FnMut(&Path) -> Option<FileId>,
166 ) -> (CrateGraph, FxHashMap<CrateId, String>) { 166 ) -> CrateGraph {
167 let mut crate_graph = CrateGraph::default(); 167 let mut crate_graph = CrateGraph::default();
168 let mut names = FxHashMap::default();
169 match self { 168 match self {
170 ProjectWorkspace::Json { project } => { 169 ProjectWorkspace::Json { project } => {
171 let mut crates = FxHashMap::default(); 170 let mut crates = FxHashMap::default();
@@ -191,6 +190,8 @@ impl ProjectWorkspace {
191 crate_graph.add_crate_root( 190 crate_graph.add_crate_root(
192 file_id, 191 file_id,
193 edition, 192 edition,
193 // FIXME json definitions can store the crate name
194 None,
194 cfg_options, 195 cfg_options,
195 Env::default(), 196 Env::default(),
196 ), 197 ),
@@ -233,11 +234,11 @@ impl ProjectWorkspace {
233 let crate_id = crate_graph.add_crate_root( 234 let crate_id = crate_graph.add_crate_root(
234 file_id, 235 file_id,
235 Edition::Edition2018, 236 Edition::Edition2018,
237 Some(krate.name(&sysroot).to_string()),
236 cfg_options, 238 cfg_options,
237 Env::default(), 239 Env::default(),
238 ); 240 );
239 sysroot_crates.insert(krate, crate_id); 241 sysroot_crates.insert(krate, crate_id);
240 names.insert(crate_id, krate.name(&sysroot).to_string());
241 } 242 }
242 } 243 }
243 for from in sysroot.crates() { 244 for from in sysroot.crates() {
@@ -277,10 +278,10 @@ impl ProjectWorkspace {
277 let crate_id = crate_graph.add_crate_root( 278 let crate_id = crate_graph.add_crate_root(
278 file_id, 279 file_id,
279 edition, 280 edition,
281 Some(pkg.name(&cargo).to_string()),
280 cfg_options, 282 cfg_options,
281 Env::default(), 283 Env::default(),
282 ); 284 );
283 names.insert(crate_id, pkg.name(&cargo).to_string());
284 if tgt.kind(&cargo) == TargetKind::Lib { 285 if tgt.kind(&cargo) == TargetKind::Lib {
285 lib_tgt = Some(crate_id); 286 lib_tgt = Some(crate_id);
286 pkg_to_lib_crate.insert(pkg, crate_id); 287 pkg_to_lib_crate.insert(pkg, crate_id);
@@ -381,7 +382,7 @@ impl ProjectWorkspace {
381 } 382 }
382 } 383 }
383 } 384 }
384 (crate_graph, names) 385 crate_graph
385 } 386 }
386 387
387 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> { 388 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 8cd08ecb6..4be987860 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -52,12 +52,11 @@ pub(crate) fn load_cargo(
52 opts 52 opts
53 }; 53 };
54 54
55 let (crate_graph, _crate_names) = 55 let crate_graph = ws.to_crate_graph(&default_cfg_options, &mut |path: &Path| {
56 ws.to_crate_graph(&default_cfg_options, &mut |path: &Path| { 56 let vfs_file = vfs.load(path);
57 let vfs_file = vfs.load(path); 57 log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
58 log::debug!("vfs file {:?} -> {:?}", path, vfs_file); 58 vfs_file.map(vfs_file_to_id)
59 vfs_file.map(vfs_file_to_id) 59 });
60 });
61 log::debug!("crate graph: {:?}", crate_graph); 60 log::debug!("crate graph: {:?}", crate_graph);
62 61
63 let source_roots = roots 62 let source_roots = roots
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 96efab844..c92cf137c 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -123,13 +123,12 @@ impl WorldState {
123 let vfs_file = vfs.load(path); 123 let vfs_file = vfs.load(path);
124 vfs_file.map(|f| FileId(f.0)) 124 vfs_file.map(|f| FileId(f.0))
125 }; 125 };
126 for ws in workspaces.iter() { 126
127 let (graph, crate_names) = ws.to_crate_graph(&default_cfg_options, &mut load); 127 workspaces.iter().map(|ws| ws.to_crate_graph(&default_cfg_options, &mut load)).for_each(
128 let shift = crate_graph.extend(graph); 128 |graph| {
129 for (crate_id, name) in crate_names { 129 crate_graph.extend(graph);
130 change.set_debug_crate_name(crate_id.shift(shift), name) 130 },
131 } 131 );
132 }
133 change.set_crate_graph(crate_graph); 132 change.set_crate_graph(crate_graph);
134 133
135 // FIXME: Figure out the multi-workspace situation 134 // FIXME: Figure out the multi-workspace situation