diff options
Diffstat (limited to 'crates/ide/src/doc_links.rs')
-rw-r--r-- | crates/ide/src/doc_links.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index de10406bc..730e0dd0a 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -221,14 +221,31 @@ fn rewrite_intra_doc_link( | |||
221 | }?; | 221 | }?; |
222 | let krate = resolved.module(db)?.krate(); | 222 | let krate = resolved.module(db)?.krate(); |
223 | let canonical_path = resolved.canonical_path(db)?; | 223 | let canonical_path = resolved.canonical_path(db)?; |
224 | let new_target = get_doc_url(db, &krate)? | 224 | let mut new_url = get_doc_url(db, &krate)? |
225 | .join(&format!("{}/", krate.display_name(db)?)) | 225 | .join(&format!("{}/", krate.display_name(db)?)) |
226 | .ok()? | 226 | .ok()? |
227 | .join(&canonical_path.replace("::", "/")) | 227 | .join(&canonical_path.replace("::", "/")) |
228 | .ok()? | 228 | .ok()? |
229 | .join(&get_symbol_filename(db, &resolved)?) | 229 | .join(&get_symbol_filename(db, &resolved)?) |
230 | .ok()? | 230 | .ok()?; |
231 | .into_string(); | 231 | |
232 | if let ModuleDef::Trait(t) = resolved { | ||
233 | let items = t.items(db); | ||
234 | if let Some(field_or_assoc_item) = items.iter().find_map(|assoc_item| { | ||
235 | if let Some(name) = assoc_item.name(db) { | ||
236 | if link.to_string() == format!("{}::{}", canonical_path, name) { | ||
237 | return Some(FieldOrAssocItem::AssocItem(*assoc_item)); | ||
238 | } | ||
239 | } | ||
240 | None | ||
241 | }) { | ||
242 | if let Some(fragment) = get_symbol_fragment(db, &field_or_assoc_item) { | ||
243 | new_url = new_url.join(&fragment).ok()?; | ||
244 | } | ||
245 | }; | ||
246 | } | ||
247 | |||
248 | let new_target = new_url.into_string(); | ||
232 | let new_title = strip_prefixes_suffixes(title); | 249 | let new_title = strip_prefixes_suffixes(title); |
233 | Some((new_target, new_title.to_string())) | 250 | Some((new_target, new_title.to_string())) |
234 | } | 251 | } |
@@ -438,10 +455,10 @@ fn get_symbol_fragment(db: &dyn HirDatabase, field_or_assoc: &FieldOrAssocItem) | |||
438 | FieldOrAssocItem::Field(field) => format!("#structfield.{}", field.name(db)), | 455 | FieldOrAssocItem::Field(field) => format!("#structfield.{}", field.name(db)), |
439 | FieldOrAssocItem::AssocItem(assoc) => match assoc { | 456 | FieldOrAssocItem::AssocItem(assoc) => match assoc { |
440 | AssocItem::Function(function) => { | 457 | AssocItem::Function(function) => { |
441 | let is_trait_method = matches!( | 458 | let is_trait_method = function |
442 | function.as_assoc_item(db).map(|assoc| assoc.container(db)), | 459 | .as_assoc_item(db) |
443 | Some(AssocItemContainer::Trait(..)) | 460 | .and_then(|assoc| assoc.containing_trait(db)) |
444 | ); | 461 | .is_some(); |
445 | // This distinction may get more complicated when specialization is available. | 462 | // This distinction may get more complicated when specialization is available. |
446 | // Rustdoc makes this decision based on whether a method 'has defaultness'. | 463 | // Rustdoc makes this decision based on whether a method 'has defaultness'. |
447 | // Currently this is only the case for provided trait methods. | 464 | // Currently this is only the case for provided trait methods. |