aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-03-16 09:47:52 +0000
committerKirill Bulatov <[email protected]>2020-03-16 09:47:52 +0000
commit059ed25a3eea97f370c190803318d5cb7885e1a9 (patch)
tree7c4b36fc3623683380caf5bd6487e3f8aa57774a
parent6bc226fa1918b8025b19cdf9d1f972f029e6a899 (diff)
Fix crate display name dashes
-rw-r--r--crates/ra_db/src/fixture.rs6
-rw-r--r--crates/ra_db/src/input.rs9
-rw-r--r--crates/ra_hir_def/src/nameres.rs9
-rw-r--r--crates/ra_ide/src/hover.rs27
-rw-r--r--crates/ra_ide/src/mock_analysis.rs2
-rw-r--r--crates/ra_project_model/src/lib.rs7
6 files changed, 40 insertions, 20 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 3dc86ca2d..3464f43df 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -64,7 +64,9 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
64 crate_graph.add_crate_root( 64 crate_graph.add_crate_root(
65 file_id, 65 file_id,
66 meta.edition, 66 meta.edition,
67 meta.krate, 67 meta.krate.map(|name| {
68 CrateName::new(&name).expect("Fixture crate name should not contain dashes")
69 }),
68 meta.cfg, 70 meta.cfg,
69 meta.env, 71 meta.env,
70 Default::default(), 72 Default::default(),
@@ -124,7 +126,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
124 let crate_id = crate_graph.add_crate_root( 126 let crate_id = crate_graph.add_crate_root(
125 file_id, 127 file_id,
126 meta.edition, 128 meta.edition,
127 Some(krate.clone()), 129 Some(CrateName::new(&krate).unwrap()),
128 meta.cfg, 130 meta.cfg,
129 meta.env, 131 meta.env,
130 Default::default(), 132 Default::default(),
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 06d40db96..a6a831afa 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -83,6 +83,7 @@ pub struct CrateGraph {
83#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 83#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
84pub struct CrateId(pub u32); 84pub struct CrateId(pub u32);
85 85
86#[derive(Debug, Clone, PartialEq, Eq)]
86pub struct CrateName(SmolStr); 87pub struct CrateName(SmolStr);
87 88
88impl CrateName { 89impl CrateName {
@@ -101,6 +102,10 @@ impl CrateName {
101 pub fn normalize_dashes(name: &str) -> CrateName { 102 pub fn normalize_dashes(name: &str) -> CrateName {
102 Self(SmolStr::new(name.replace('-', "_"))) 103 Self(SmolStr::new(name.replace('-', "_")))
103 } 104 }
105
106 pub fn get_name(&self) -> String {
107 self.0.to_string()
108 }
104} 109}
105 110
106#[derive(Debug, Clone, PartialEq, Eq)] 111#[derive(Debug, Clone, PartialEq, Eq)]
@@ -110,7 +115,7 @@ pub struct CrateData {
110 /// The name to display to the end user. 115 /// The name to display to the end user.
111 /// This actual crate name can be different in a particular dependent crate 116 /// This actual crate name can be different in a particular dependent crate
112 /// or may even be missing for some cases, such as a dummy crate for the code snippet. 117 /// or may even be missing for some cases, such as a dummy crate for the code snippet.
113 pub display_name: Option<String>, 118 pub display_name: Option<CrateName>,
114 pub cfg_options: CfgOptions, 119 pub cfg_options: CfgOptions,
115 pub env: Env, 120 pub env: Env,
116 pub extern_source: ExternSource, 121 pub extern_source: ExternSource,
@@ -150,7 +155,7 @@ impl CrateGraph {
150 &mut self, 155 &mut self,
151 file_id: FileId, 156 file_id: FileId,
152 edition: Edition, 157 edition: Edition,
153 display_name: Option<String>, 158 display_name: Option<CrateName>,
154 cfg_options: CfgOptions, 159 cfg_options: CfgOptions,
155 env: Env, 160 env: Env,
156 extern_source: ExternSource, 161 extern_source: ExternSource,
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 81eac52ad..87992854a 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -177,8 +177,13 @@ pub struct ModuleData {
177 177
178impl CrateDefMap { 178impl CrateDefMap {
179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
180 let _p = profile("crate_def_map_query") 180 let _p = profile("crate_def_map_query").detail(|| {
181 .detail(|| db.crate_graph()[krate].display_name.clone().unwrap_or_default()); 181 db.crate_graph()[krate]
182 .display_name
183 .as_ref()
184 .map(|name| name.get_name())
185 .unwrap_or_default()
186 });
182 let def_map = { 187 let def_map = {
183 let edition = db.crate_graph()[krate].edition; 188 let edition = db.crate_graph()[krate].edition;
184 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); 189 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default();
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 3bdd61a2e..d1deca96b 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -94,17 +94,22 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
94 94
95fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { 95fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
96 let mod_path = def.module(db).map(|module| { 96 let mod_path = def.module(db).map(|module| {
97 once(db.crate_graph()[module.krate().into()].display_name.clone()) 97 once(
98 .chain( 98 db.crate_graph()[module.krate().into()]
99 module 99 .display_name
100 .path_to_root(db) 100 .as_ref()
101 .into_iter() 101 .map(|name| name.get_name()),
102 .rev() 102 )
103 .map(|it| it.name(db).map(|name| name.to_string())), 103 .chain(
104 ) 104 module
105 .chain(once(definition_owner_name(db, def))) 105 .path_to_root(db)
106 .flatten() 106 .into_iter()
107 .join("::") 107 .rev()
108 .map(|it| it.name(db).map(|name| name.to_string())),
109 )
110 .chain(once(definition_owner_name(db, def)))
111 .flatten()
112 .join("::")
108 }); 113 });
109 mod_path // FIXME: replace dashes with underscores in crate display name 114 mod_path // FIXME: replace dashes with underscores in crate display name
110} 115}
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index 25816cf6f..2cf77a31f 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -109,7 +109,7 @@ impl MockAnalysis {
109 let other_crate = crate_graph.add_crate_root( 109 let other_crate = crate_graph.add_crate_root(
110 file_id, 110 file_id,
111 Edition2018, 111 Edition2018,
112 Some(crate_name.to_owned()), 112 Some(CrateName::new(crate_name).unwrap()),
113 cfg_options, 113 cfg_options,
114 Env::default(), 114 Env::default(),
115 Default::default(), 115 Default::default(),
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index a6274709d..897874813 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -245,7 +245,10 @@ impl ProjectWorkspace {
245 let crate_id = crate_graph.add_crate_root( 245 let crate_id = crate_graph.add_crate_root(
246 file_id, 246 file_id,
247 Edition::Edition2018, 247 Edition::Edition2018,
248 Some(krate.name(&sysroot).to_string()), 248 Some(
249 CrateName::new(krate.name(&sysroot))
250 .expect("Sysroot crate names should not contain dashes"),
251 ),
249 cfg_options, 252 cfg_options,
250 env, 253 env,
251 extern_source, 254 extern_source,
@@ -296,7 +299,7 @@ impl ProjectWorkspace {
296 let crate_id = crate_graph.add_crate_root( 299 let crate_id = crate_graph.add_crate_root(
297 file_id, 300 file_id,
298 edition, 301 edition,
299 Some(pkg.name(&cargo).to_string()), 302 Some(CrateName::normalize_dashes(pkg.name(&cargo))),
300 cfg_options, 303 cfg_options,
301 env, 304 env,
302 extern_source, 305 extern_source,