aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-20 14:38:11 +0100
committerAleksey Kladov <[email protected]>2020-10-20 14:38:11 +0100
commitaf4e75533f2c071330e740e2fa94b131e3a2b538 (patch)
tree6f517a43814751d8b1ea478b5ed03baf57b4f0b5 /crates
parentbe762ccccd5a86632e60351518528d078785a3e2 (diff)
Rename declaration_name -> display_name
Declaration names sounds like a name of declaration -- something you can use for analysis. It empathically isn't, and is just a label displayed in various UI. It's important not to confuse the two, least we accidentally mix semantics with UI (I believe, there's already a case of this in the FamousDefs at least).
Diffstat (limited to 'crates')
-rw-r--r--crates/assists/src/utils.rs2
-rw-r--r--crates/base_db/src/input.rs20
-rw-r--r--crates/hir/src/code_model.rs4
-rw-r--r--crates/hir_def/src/import_map.rs6
-rw-r--r--crates/hir_def/src/nameres.rs6
-rw-r--r--crates/ide/src/doc_links.rs8
-rw-r--r--crates/ide/src/hover.rs2
-rw-r--r--crates/ide/src/inlay_hints.rs2
-rw-r--r--crates/ide/src/prime_caches.rs3
-rw-r--r--crates/ide/src/status.rs2
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs8
11 files changed, 28 insertions, 35 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs
index b37b0d2b6..4e89a7aed 100644
--- a/crates/assists/src/utils.rs
+++ b/crates/assists/src/utils.rs
@@ -406,7 +406,7 @@ pub use prelude::*;
406 let std_crate = path.next()?; 406 let std_crate = path.next()?;
407 let std_crate = if self 407 let std_crate = if self
408 .1 408 .1
409 .declaration_name(db) 409 .display_name(db)
410 .map(|name| name.to_string() == std_crate) 410 .map(|name| name.to_string() == std_crate)
411 .unwrap_or(false) 411 .unwrap_or(false)
412 { 412 {
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index b870e2cee..eb3aac88d 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -127,11 +127,13 @@ impl PartialEq for ProcMacro {
127pub struct CrateData { 127pub struct CrateData {
128 pub root_file_id: FileId, 128 pub root_file_id: FileId,
129 pub edition: Edition, 129 pub edition: Edition,
130 /// A name used in the package's project declaration: for Cargo projects, it's [package].name, 130 /// A name used in the package's project declaration: for Cargo projects,
131 /// can be different for other project types or even absent (a dummy crate for the code snippet, for example). 131 /// it's [package].name, can be different for other project types or even
132 /// NOTE: The crate can be referenced as a dependency under a different name, 132 /// absent (a dummy crate for the code snippet, for example).
133 /// this one should be used when working with crate hierarchies. 133 ///
134 pub declaration_name: Option<CrateName>, 134 /// For purposes of analysis, crates are anonymous (only names in
135 /// `Dependency` matters), this name should only be used for UI.
136 pub display_name: Option<CrateName>,
135 pub cfg_options: CfgOptions, 137 pub cfg_options: CfgOptions,
136 pub env: Env, 138 pub env: Env,
137 pub dependencies: Vec<Dependency>, 139 pub dependencies: Vec<Dependency>,
@@ -160,7 +162,7 @@ impl CrateGraph {
160 &mut self, 162 &mut self,
161 file_id: FileId, 163 file_id: FileId,
162 edition: Edition, 164 edition: Edition,
163 declaration_name: Option<CrateName>, 165 display_name: Option<CrateName>,
164 cfg_options: CfgOptions, 166 cfg_options: CfgOptions,
165 env: Env, 167 env: Env,
166 proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>, 168 proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
@@ -171,7 +173,7 @@ impl CrateGraph {
171 let data = CrateData { 173 let data = CrateData {
172 root_file_id: file_id, 174 root_file_id: file_id,
173 edition, 175 edition,
174 declaration_name, 176 display_name,
175 cfg_options, 177 cfg_options,
176 env, 178 env,
177 proc_macro, 179 proc_macro,
@@ -310,8 +312,8 @@ impl CrateGraph {
310 } 312 }
311 } 313 }
312 314
313 fn hacky_find_crate(&self, declaration_name: &str) -> Option<CrateId> { 315 fn hacky_find_crate(&self, display_name: &str) -> Option<CrateId> {
314 self.iter().find(|it| self[*it].declaration_name.as_deref() == Some(declaration_name)) 316 self.iter().find(|it| self[*it].display_name.as_deref() == Some(display_name))
315 } 317 }
316} 318}
317 319
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index b65be4fe1..64f3fbe31 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -103,8 +103,8 @@ impl Crate {
103 db.crate_graph()[self.id].edition 103 db.crate_graph()[self.id].edition
104 } 104 }
105 105
106 pub fn declaration_name(self, db: &dyn HirDatabase) -> Option<CrateName> { 106 pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
107 db.crate_graph()[self.id].declaration_name.clone() 107 db.crate_graph()[self.id].display_name.clone()
108 } 108 }
109 109
110 pub fn query_external_importables( 110 pub fn query_external_importables(
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index 028cae2e7..1e24f29a8 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -356,7 +356,7 @@ mod tests {
356 let krate = crate_graph 356 let krate = crate_graph
357 .iter() 357 .iter()
358 .find(|krate| { 358 .find(|krate| {
359 crate_graph[*krate].declaration_name.as_ref().map(|n| n.to_string()) 359 crate_graph[*krate].display_name.as_ref().map(|n| n.to_string())
360 == Some(crate_name.to_string()) 360 == Some(crate_name.to_string())
361 }) 361 })
362 .unwrap(); 362 .unwrap();
@@ -375,7 +375,7 @@ mod tests {
375 let path = map.path_of(item).unwrap(); 375 let path = map.path_of(item).unwrap();
376 format!( 376 format!(
377 "{}::{} ({})\n", 377 "{}::{} ({})\n",
378 crate_graph[krate].declaration_name.as_ref().unwrap(), 378 crate_graph[krate].display_name.as_ref().unwrap(),
379 path, 379 path,
380 mark 380 mark
381 ) 381 )
@@ -416,7 +416,7 @@ mod tests {
416 .iter() 416 .iter()
417 .filter_map(|krate| { 417 .filter_map(|krate| {
418 let cdata = &crate_graph[krate]; 418 let cdata = &crate_graph[krate];
419 let name = cdata.declaration_name.as_ref()?; 419 let name = cdata.display_name.as_ref()?;
420 420
421 let map = db.import_map(krate); 421 let map = db.import_map(krate);
422 422
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index 464ffef21..3d04f81c6 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -172,11 +172,7 @@ pub struct ModuleData {
172impl CrateDefMap { 172impl CrateDefMap {
173 pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 173 pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
174 let _p = profile::span("crate_def_map_query").detail(|| { 174 let _p = profile::span("crate_def_map_query").detail(|| {
175 db.crate_graph()[krate] 175 db.crate_graph()[krate].display_name.as_deref().unwrap_or_default().to_string()
176 .declaration_name
177 .as_ref()
178 .map(ToString::to_string)
179 .unwrap_or_default()
180 }); 176 });
181 let def_map = { 177 let def_map = {
182 let edition = db.crate_graph()[krate].edition; 178 let edition = db.crate_graph()[krate].edition;
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index d9dc63b33..b9d8b8a2b 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -130,7 +130,7 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
130 let module = definition.module(db)?; 130 let module = definition.module(db)?;
131 let krate = module.krate(); 131 let krate = module.krate();
132 let import_map = db.import_map(krate.into()); 132 let import_map = db.import_map(krate.into());
133 let base = once(krate.declaration_name(db)?.to_string()) 133 let base = once(krate.display_name(db)?.to_string())
134 .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) 134 .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string()))
135 .join("/"); 135 .join("/");
136 136
@@ -188,7 +188,7 @@ fn rewrite_intra_doc_link(
188 let krate = resolved.module(db)?.krate(); 188 let krate = resolved.module(db)?.krate();
189 let canonical_path = resolved.canonical_path(db)?; 189 let canonical_path = resolved.canonical_path(db)?;
190 let new_target = get_doc_url(db, &krate)? 190 let new_target = get_doc_url(db, &krate)?
191 .join(&format!("{}/", krate.declaration_name(db)?)) 191 .join(&format!("{}/", krate.display_name(db)?))
192 .ok()? 192 .ok()?
193 .join(&canonical_path.replace("::", "/")) 193 .join(&canonical_path.replace("::", "/"))
194 .ok()? 194 .ok()?
@@ -208,7 +208,7 @@ fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option<S
208 let module = def.module(db)?; 208 let module = def.module(db)?;
209 let krate = module.krate(); 209 let krate = module.krate();
210 let canonical_path = def.canonical_path(db)?; 210 let canonical_path = def.canonical_path(db)?;
211 let base = format!("{}/{}", krate.declaration_name(db)?, canonical_path.replace("::", "/")); 211 let base = format!("{}/{}", krate.display_name(db)?, canonical_path.replace("::", "/"));
212 212
213 get_doc_url(db, &krate) 213 get_doc_url(db, &krate)
214 .and_then(|url| url.join(&base).ok()) 214 .and_then(|url| url.join(&base).ok())
@@ -357,7 +357,7 @@ fn get_doc_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
357 // 357 //
358 // FIXME: clicking on the link should just open the file in the editor, 358 // FIXME: clicking on the link should just open the file in the editor,
359 // instead of falling back to external urls. 359 // instead of falling back to external urls.
360 Some(format!("https://docs.rs/{}/*/", krate.declaration_name(db)?)) 360 Some(format!("https://docs.rs/{}/*/", krate.display_name(db)?))
361 }) 361 })
362 .and_then(|s| Url::parse(&s).ok()) 362 .and_then(|s| Url::parse(&s).ok())
363} 363}
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 845333e2a..6466422c5 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -300,7 +300,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
300 300
301fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String { 301fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
302 let crate_name = 302 let crate_name =
303 db.crate_graph()[module.krate().into()].declaration_name.as_ref().map(ToString::to_string); 303 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
304 let module_path = module 304 let module_path = module
305 .path_to_root(db) 305 .path_to_root(db)
306 .into_iter() 306 .into_iter()
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index e2079bbcf..f5f366354 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -215,7 +215,7 @@ fn hint_iterator(
215 .last() 215 .last()
216 .and_then(|strukt| strukt.as_adt())?; 216 .and_then(|strukt| strukt.as_adt())?;
217 let krate = strukt.krate(db)?; 217 let krate = strukt.krate(db)?;
218 if krate.declaration_name(db).as_deref() != Some("core") { 218 if krate.display_name(db).as_deref() != Some("core") {
219 return None; 219 return None;
220 } 220 }
221 let iter_trait = FamousDefs(sema, krate).core_iter_Iterator()?; 221 let iter_trait = FamousDefs(sema, krate).core_iter_Iterator()?;
diff --git a/crates/ide/src/prime_caches.rs b/crates/ide/src/prime_caches.rs
index 9687c2734..6944dbcd2 100644
--- a/crates/ide/src/prime_caches.rs
+++ b/crates/ide/src/prime_caches.rs
@@ -32,8 +32,7 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress)
32 // Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks 32 // Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks
33 // cancellation, so we cannot use rayon. 33 // cancellation, so we cannot use rayon.
34 for (i, krate) in topo.iter().enumerate() { 34 for (i, krate) in topo.iter().enumerate() {
35 let crate_name = 35 let crate_name = graph[*krate].display_name.as_deref().unwrap_or_default().to_string();
36 graph[*krate].declaration_name.as_ref().map(ToString::to_string).unwrap_or_default();
37 36
38 cb(PrimeCachesProgress::StartedOnCrate { 37 cb(PrimeCachesProgress::StartedOnCrate {
39 on_crate: crate_name, 38 on_crate: crate_name,
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index f67f10491..0af84daa0 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -45,7 +45,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
45 match krate { 45 match krate {
46 Some(krate) => { 46 Some(krate) => {
47 let crate_graph = db.crate_graph(); 47 let crate_graph = db.crate_graph();
48 let display_crate = |krate: CrateId| match &crate_graph[krate].declaration_name { 48 let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
49 Some(it) => format!("{}({:?})", it, krate), 49 Some(it) => format!("{}({:?})", it, krate),
50 None => format!("{:?}", krate), 50 None => format!("{:?}", krate),
51 }; 51 };
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index d1d3b12f8..a89993a2b 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -36,12 +36,8 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -
36 for module in work { 36 for module in work {
37 let file_id = module.definition_source(db).file_id.original_file(db); 37 let file_id = module.definition_source(db).file_id.original_file(db);
38 if !visited_files.contains(&file_id) { 38 if !visited_files.contains(&file_id) {
39 let crate_name = module 39 let crate_name =
40 .krate() 40 module.krate().display_name(db).as_deref().unwrap_or("unknown").to_string();
41 .declaration_name(db)
42 .as_ref()
43 .map(ToString::to_string)
44 .unwrap_or_else(|| "unknown".to_string());
45 println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id)); 41 println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id));
46 for diagnostic in analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap() 42 for diagnostic in analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap()
47 { 43 {