From cae2e859ffbf2b435c8675838e450b66d4c6153e Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 2 Oct 2020 20:59:32 +0300 Subject: Add a dash test --- crates/ide/src/hover.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'crates/ide') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 9cf02f0a3..acdb51f26 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -3163,4 +3163,34 @@ fn main() { let s<|>t = test().get(); } "#]], ); } + + #[test] + fn hover_displays_normalized_crate_names() { + check( + r#" +//- /lib.rs crate:name-with-dashes +pub mod wrapper { + pub struct Thing { x: u32 } + + impl Thing { + pub fn new() -> Thing { Thing { x: 0 } } + } +} + +//- /main.rs crate:main deps:name-with-dashes +fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); } +"#, + expect![[r#" + *new* + + ```rust + name_with_dashes::wrapper::Thing + ``` + + ```rust + pub fn new() -> Thing + ``` + "#]], + ) + } } -- cgit v1.2.3 From 9d19e5b962f77259dd1334b9edb4da4de54f0987 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 2 Oct 2020 21:38:22 +0300 Subject: Properly name the field --- crates/ide/src/hover.rs | 2 +- crates/ide/src/link_rewrite.rs | 6 +++--- crates/ide/src/status.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ide') 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 fn render_path(db: &RootDatabase, module: Module, item_name: Option) -> String { let crate_name = - db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string); + db.crate_graph()[module.krate().into()].declaration_name.as_ref().map(ToString::to_string); let module_path = module .path_to_root(db) .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( let krate = resolved.module(db)?.krate(); let canonical_path = resolved.canonical_path(db)?; let new_target = get_doc_url(db, &krate)? - .join(&format!("{}/", krate.display_name(db)?)) + .join(&format!("{}/", krate.declaration_name(db)?)) .ok()? .join(&canonical_path.replace("::", "/")) .ok()? @@ -127,7 +127,7 @@ fn rewrite_url_link(db: &RootDatabase, def: ModuleDef, target: &str) -> Option Option { // // FIXME: clicking on the link should just open the file in the editor, // instead of falling back to external urls. - Some(format!("https://docs.rs/{}/*/", krate.display_name(db)?)) + Some(format!("https://docs.rs/{}/*/", krate.declaration_name(db)?)) }) .and_then(|s| Url::parse(&s).ok()) } 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) -> String { match krate { Some(krate) => { let crate_graph = db.crate_graph(); - let display_crate = |krate: CrateId| match &crate_graph[krate].display_name { + let display_crate = |krate: CrateId| match &crate_graph[krate].declaration_name { Some(it) => format!("{}({:?})", it, krate), None => format!("{:?}", krate), }; -- cgit v1.2.3