diff options
Diffstat (limited to 'crates/ide/src/hover.rs')
-rw-r--r-- | crates/ide/src/hover.rs | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 614433417..9de653739 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use either::Either; | 1 | use either::Either; |
2 | use hir::{ | 2 | use hir::{ |
3 | AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module, | 3 | AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, InFile, Module, |
4 | ModuleDef, Semantics, | 4 | ModuleDef, Semantics, |
5 | }; | 5 | }; |
6 | use ide_db::{ | 6 | use ide_db::{ |
@@ -16,8 +16,8 @@ use syntax::{ast, match_ast, AstNode, AstToken, SyntaxKind::*, SyntaxToken, Toke | |||
16 | use crate::{ | 16 | use crate::{ |
17 | display::{macro_label, TryToNav}, | 17 | display::{macro_label, TryToNav}, |
18 | doc_links::{ | 18 | doc_links::{ |
19 | doc_owner_to_def, extract_positioned_link_from_comment, remove_links, | 19 | doc_attributes, extract_definitions_from_markdown, remove_links, resolve_doc_path_for_def, |
20 | resolve_doc_path_for_def, rewrite_links, | 20 | rewrite_links, |
21 | }, | 21 | }, |
22 | markdown_remove::remove_markdown, | 22 | markdown_remove::remove_markdown, |
23 | markup::Markup, | 23 | markup::Markup, |
@@ -116,11 +116,19 @@ pub(crate) fn hover( | |||
116 | ), | 116 | ), |
117 | 117 | ||
118 | _ => ast::Comment::cast(token.clone()) | 118 | _ => ast::Comment::cast(token.clone()) |
119 | .and_then(|comment| { | 119 | .and_then(|_| { |
120 | let (attributes, def) = doc_attributes(&sema, &node)?; | ||
121 | let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?; | ||
120 | let (idl_range, link, ns) = | 122 | let (idl_range, link, ns) = |
121 | extract_positioned_link_from_comment(position.offset, &comment)?; | 123 | extract_definitions_from_markdown(docs.as_str()).into_iter().find_map(|(range, link, ns)| { |
124 | let InFile { file_id, value: range } = doc_mapping.map(range.clone())?; | ||
125 | if file_id == position.file_id.into() && range.contains(position.offset) { | ||
126 | Some((range, link, ns)) | ||
127 | } else { | ||
128 | None | ||
129 | } | ||
130 | })?; | ||
122 | range = Some(idl_range); | 131 | range = Some(idl_range); |
123 | let def = doc_owner_to_def(&sema, &node)?; | ||
124 | resolve_doc_path_for_def(db, def, &link, ns) | 132 | resolve_doc_path_for_def(db, def, &link, ns) |
125 | }) | 133 | }) |
126 | .map(Definition::ModuleDef), | 134 | .map(Definition::ModuleDef), |
@@ -3814,23 +3822,33 @@ fn main() { | |||
3814 | fn hover_intra_doc_links() { | 3822 | fn hover_intra_doc_links() { |
3815 | check( | 3823 | check( |
3816 | r#" | 3824 | r#" |
3817 | /// This is the [`foo`](foo$0) function. | 3825 | |
3818 | fn foo() {} | 3826 | pub mod theitem { |
3827 | /// This is the item. Cool! | ||
3828 | pub struct TheItem; | ||
3829 | } | ||
3830 | |||
3831 | /// Gives you a [`TheItem$0`]. | ||
3832 | /// | ||
3833 | /// [`TheItem`]: theitem::TheItem | ||
3834 | pub fn gimme() -> theitem::TheItem { | ||
3835 | theitem::TheItem | ||
3836 | } | ||
3819 | "#, | 3837 | "#, |
3820 | expect![[r#" | 3838 | expect![[r#" |
3821 | *[`foo`](foo)* | 3839 | *[`TheItem`]* |
3822 | 3840 | ||
3823 | ```rust | 3841 | ```rust |
3824 | test | 3842 | test::theitem |
3825 | ``` | 3843 | ``` |
3826 | 3844 | ||
3827 | ```rust | 3845 | ```rust |
3828 | fn foo() | 3846 | pub struct TheItem |
3829 | ``` | 3847 | ``` |
3830 | 3848 | ||
3831 | --- | 3849 | --- |
3832 | 3850 | ||
3833 | This is the [`foo`](https://docs.rs/test/*/test/fn.foo.html) function. | 3851 | This is the item. Cool! |
3834 | "#]], | 3852 | "#]], |
3835 | ); | 3853 | ); |
3836 | } | 3854 | } |