aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-10-02 19:38:22 +0100
committerKirill Bulatov <[email protected]>2020-10-02 19:38:22 +0100
commit9d19e5b962f77259dd1334b9edb4da4de54f0987 (patch)
tree46a6713bc101e450377ec225573635641438da97
parent99952f3be254394a5c70ce8fb8436d76c779ed71 (diff)
Properly name the field
-rw-r--r--crates/base_db/src/input.rs13
-rw-r--r--crates/hir/src/code_model.rs4
-rw-r--r--crates/hir_def/src/import_map.rs10
-rw-r--r--crates/hir_def/src/nameres.rs2
-rw-r--r--crates/ide/src/hover.rs2
-rw-r--r--crates/ide/src/link_rewrite.rs6
-rw-r--r--crates/ide/src/status.rs2
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs11
8 files changed, 26 insertions, 24 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index 251a7b245..c330314d4 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -127,10 +127,11 @@ 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 /// The name to display to the end user. 130 /// A name used in the package's project declaration: for Cargo projects, it's [package].name,
131 /// This actual crate name can be different in a particular dependent crate 131 /// can be different for other project types or even absent (a dummy crate for the code snippet, for example).
132 /// or may even be missing for some cases, such as a dummy crate for the code snippet. 132 /// NOTE: The crate can be referenced as a dependency under a different name,
133 pub display_name: Option<CrateName>, 133 /// this one should be used when working with crate hierarchies.
134 pub declaration_name: Option<CrateName>,
134 pub cfg_options: CfgOptions, 135 pub cfg_options: CfgOptions,
135 pub env: Env, 136 pub env: Env,
136 pub dependencies: Vec<Dependency>, 137 pub dependencies: Vec<Dependency>,
@@ -159,7 +160,7 @@ impl CrateGraph {
159 &mut self, 160 &mut self,
160 file_id: FileId, 161 file_id: FileId,
161 edition: Edition, 162 edition: Edition,
162 display_name: Option<CrateName>, 163 declaration_name: Option<CrateName>,
163 cfg_options: CfgOptions, 164 cfg_options: CfgOptions,
164 env: Env, 165 env: Env,
165 proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>, 166 proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
@@ -170,7 +171,7 @@ impl CrateGraph {
170 let data = CrateData { 171 let data = CrateData {
171 root_file_id: file_id, 172 root_file_id: file_id,
172 edition, 173 edition,
173 display_name, 174 declaration_name,
174 cfg_options, 175 cfg_options,
175 env, 176 env,
176 proc_macro, 177 proc_macro,
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index f3388da32..a19b0fad7 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -98,8 +98,8 @@ impl Crate {
98 db.crate_graph()[self.id].edition 98 db.crate_graph()[self.id].edition
99 } 99 }
100 100
101 pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> { 101 pub fn declaration_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
102 db.crate_graph()[self.id].display_name.clone() 102 db.crate_graph()[self.id].declaration_name.clone()
103 } 103 }
104 104
105 pub fn query_external_importables( 105 pub fn query_external_importables(
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs
index a442fb63a..44bfe1593 100644
--- a/crates/hir_def/src/import_map.rs
+++ b/crates/hir_def/src/import_map.rs
@@ -334,14 +334,14 @@ mod tests {
334 334
335 use super::*; 335 use super::*;
336 336
337 fn check_search(ra_fixture: &str, krate_name: &str, query: Query, expect: Expect) { 337 fn check_search(ra_fixture: &str, crate_name: &str, query: Query, expect: Expect) {
338 let db = TestDB::with_files(ra_fixture); 338 let db = TestDB::with_files(ra_fixture);
339 let crate_graph = db.crate_graph(); 339 let crate_graph = db.crate_graph();
340 let krate = crate_graph 340 let krate = crate_graph
341 .iter() 341 .iter()
342 .find(|krate| { 342 .find(|krate| {
343 crate_graph[*krate].display_name.as_ref().map(|n| n.to_string()) 343 crate_graph[*krate].declaration_name.as_ref().map(|n| n.to_string())
344 == Some(krate_name.to_string()) 344 == Some(crate_name.to_string())
345 }) 345 })
346 .unwrap(); 346 .unwrap();
347 347
@@ -359,7 +359,7 @@ mod tests {
359 let path = map.path_of(item).unwrap(); 359 let path = map.path_of(item).unwrap();
360 format!( 360 format!(
361 "{}::{} ({})\n", 361 "{}::{} ({})\n",
362 crate_graph[krate].display_name.as_ref().unwrap(), 362 crate_graph[krate].declaration_name.as_ref().unwrap(),
363 path, 363 path,
364 mark 364 mark
365 ) 365 )
@@ -400,7 +400,7 @@ mod tests {
400 .iter() 400 .iter()
401 .filter_map(|krate| { 401 .filter_map(|krate| {
402 let cdata = &crate_graph[krate]; 402 let cdata = &crate_graph[krate];
403 let name = cdata.display_name.as_ref()?; 403 let name = cdata.declaration_name.as_ref()?;
404 404
405 let map = db.import_map(krate); 405 let map = db.import_map(krate);
406 406
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index 5e4d73c1f..464ffef21 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -173,7 +173,7 @@ impl 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]
176 .display_name 176 .declaration_name
177 .as_ref() 177 .as_ref()
178 .map(ToString::to_string) 178 .map(ToString::to_string)
179 .unwrap_or_default() 179 .unwrap_or_default()
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index acdb51f26..4521d72cc 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -289,7 +289,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
289 289
290fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String { 290fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String {
291 let crate_name = 291 let crate_name =
292 db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string); 292 db.crate_graph()[module.krate().into()].declaration_name.as_ref().map(ToString::to_string);
293 let module_path = module 293 let module_path = module
294 .path_to_root(db) 294 .path_to_root(db)
295 .into_iter() 295 .into_iter()
diff --git a/crates/ide/src/link_rewrite.rs b/crates/ide/src/link_rewrite.rs
index a16f90e17..c317a2379 100644
--- a/crates/ide/src/link_rewrite.rs
+++ b/crates/ide/src/link_rewrite.rs
@@ -107,7 +107,7 @@ fn rewrite_intra_doc_link(
107 let krate = resolved.module(db)?.krate(); 107 let krate = resolved.module(db)?.krate();
108 let canonical_path = resolved.canonical_path(db)?; 108 let canonical_path = resolved.canonical_path(db)?;
109 let new_target = get_doc_url(db, &krate)? 109 let new_target = get_doc_url(db, &krate)?
110 .join(&format!("{}/", krate.display_name(db)?)) 110 .join(&format!("{}/", krate.declaration_name(db)?))
111 .ok()? 111 .ok()?
112 .join(&canonical_path.replace("::", "/")) 112 .join(&canonical_path.replace("::", "/"))
113 .ok()? 113 .ok()?
@@ -127,7 +127,7 @@ fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option<S
127 let module = def.module(db)?; 127 let module = def.module(db)?;
128 let krate = module.krate(); 128 let krate = module.krate();
129 let canonical_path = def.canonical_path(db)?; 129 let canonical_path = def.canonical_path(db)?;
130 let base = format!("{}/{}", krate.display_name(db)?, canonical_path.replace("::", "/")); 130 let base = format!("{}/{}", krate.declaration_name(db)?, canonical_path.replace("::", "/"));
131 131
132 get_doc_url(db, &krate) 132 get_doc_url(db, &krate)
133 .and_then(|url| url.join(&base).ok()) 133 .and_then(|url| url.join(&base).ok())
@@ -248,7 +248,7 @@ fn get_doc_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
248 // 248 //
249 // FIXME: clicking on the link should just open the file in the editor, 249 // FIXME: clicking on the link should just open the file in the editor,
250 // instead of falling back to external urls. 250 // instead of falling back to external urls.
251 Some(format!("https://docs.rs/{}/*/", krate.display_name(db)?)) 251 Some(format!("https://docs.rs/{}/*/", krate.declaration_name(db)?))
252 }) 252 })
253 .and_then(|s| Url::parse(&s).ok()) 253 .and_then(|s| Url::parse(&s).ok())
254} 254}
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index 0af84daa0..f67f10491 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].display_name { 48 let display_crate = |krate: CrateId| match &crate_graph[krate].declaration_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 f3b6c900e..d1d3b12f8 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -36,11 +36,12 @@ 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 = if let Some(name) = module.krate().display_name(db) { 39 let crate_name = module
40 format!("{}", name) 40 .krate()
41 } else { 41 .declaration_name(db)
42 String::from("unknown") 42 .as_ref()
43 }; 43 .map(ToString::to_string)
44 .unwrap_or_else(|| "unknown".to_string());
44 println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id)); 45 println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id));
45 for diagnostic in analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap() 46 for diagnostic in analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap()
46 { 47 {