diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-06 12:51:15 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-06 12:51:15 +0100 |
commit | 87cb840a4e140a49946235823384694da58c2a5a (patch) | |
tree | 4e6ce0749103bdf8e373b3d12472866bdc10d4c8 /crates/ide | |
parent | af0e54a566ab8c8be9b39a628aaa4992f161695c (diff) | |
parent | 9d19e5b962f77259dd1334b9edb4da4de54f0987 (diff) |
Merge #6124
6124: Better normalized crate name usage r=jonas-schievink a=SomeoneToIgnore
Closes https://github.com/rust-analyzer/rust-analyzer/issues/5343
Closes https://github.com/rust-analyzer/rust-analyzer/issues/5932
Uses normalized name for code snippets (to be able to test the fix), hover messages and documentation rewrite links (are there any tests for those?).
Also renamed the field to better resemble the semantics.
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/hover.rs | 32 | ||||
-rw-r--r-- | crates/ide/src/link_rewrite.rs | 6 | ||||
-rw-r--r-- | crates/ide/src/status.rs | 2 |
3 files changed, 35 insertions, 5 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 9cf02f0a3..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 | ||
290 | fn render_path(db: &RootDatabase, module: Module, item_name: Option<String>) -> String { | 290 | fn 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() |
@@ -3163,4 +3163,34 @@ fn main() { let s<|>t = test().get(); } | |||
3163 | "#]], | 3163 | "#]], |
3164 | ); | 3164 | ); |
3165 | } | 3165 | } |
3166 | |||
3167 | #[test] | ||
3168 | fn hover_displays_normalized_crate_names() { | ||
3169 | check( | ||
3170 | r#" | ||
3171 | //- /lib.rs crate:name-with-dashes | ||
3172 | pub mod wrapper { | ||
3173 | pub struct Thing { x: u32 } | ||
3174 | |||
3175 | impl Thing { | ||
3176 | pub fn new() -> Thing { Thing { x: 0 } } | ||
3177 | } | ||
3178 | } | ||
3179 | |||
3180 | //- /main.rs crate:main deps:name-with-dashes | ||
3181 | fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); } | ||
3182 | "#, | ||
3183 | expect![[r#" | ||
3184 | *new* | ||
3185 | |||
3186 | ```rust | ||
3187 | name_with_dashes::wrapper::Thing | ||
3188 | ``` | ||
3189 | |||
3190 | ```rust | ||
3191 | pub fn new() -> Thing | ||
3192 | ``` | ||
3193 | "#]], | ||
3194 | ) | ||
3195 | } | ||
3166 | } | 3196 | } |
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 | }; |