aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/goto_definition.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-29 20:23:45 +0100
committerLukas Wirth <[email protected]>2021-03-30 13:03:32 +0100
commit9df78ec4a4e41ca94b25f292aba90e266f104f02 (patch)
tree0b670a721b9fd5de261de18b871f20552e23f0fb /crates/ide/src/goto_definition.rs
parent0b68e03bf56c00f63fcc65e7879cc64c6d5c4f30 (diff)
Properly resolve intra doc links in hover and goto_definition
Diffstat (limited to 'crates/ide/src/goto_definition.rs')
-rw-r--r--crates/ide/src/goto_definition.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index c6556c487..4e4d1b200 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -31,7 +31,8 @@ pub(crate) fn goto_definition(
31 let token = sema.descend_into_macros(original_token.clone()); 31 let token = sema.descend_into_macros(original_token.clone());
32 let parent = token.parent()?; 32 let parent = token.parent()?;
33 if let Some(comment) = ast::Comment::cast(token) { 33 if let Some(comment) = ast::Comment::cast(token) {
34 let (_, link, ns) = extract_positioned_link_from_comment(position.offset, &comment)?; 34 let docs = doc_owner_to_def(&sema, &parent)?.docs(db)?;
35 let (_, link, ns) = extract_positioned_link_from_comment(position.offset, &comment, docs)?;
35 let def = doc_owner_to_def(&sema, &parent)?; 36 let def = doc_owner_to_def(&sema, &parent)?;
36 let nav = resolve_doc_path_for_def(db, def, &link, ns)?.try_to_nav(db)?; 37 let nav = resolve_doc_path_for_def(db, def, &link, ns)?.try_to_nav(db)?;
37 return Some(RangeInfo::new(original_token.text_range(), vec![nav])); 38 return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
@@ -1158,4 +1159,25 @@ fn fn_macro() {}
1158 "#, 1159 "#,
1159 ) 1160 )
1160 } 1161 }
1162
1163 #[test]
1164 fn goto_intra_doc_links() {
1165 check(
1166 r#"
1167
1168pub mod theitem {
1169 /// This is the item. Cool!
1170 pub struct TheItem;
1171 //^^^^^^^
1172}
1173
1174/// Gives you a [`TheItem$0`].
1175///
1176/// [`TheItem`]: theitem::TheItem
1177pub fn gimme() -> theitem::TheItem {
1178 theitem::TheItem
1179}
1180"#,
1181 );
1182 }
1161} 1183}