@@ -12,7 +12,9 @@ use pulldown_cmark_to_cmark::{Options as CMarkOptions, cmark_resume_with_options
12
12
use stdx:: format_to;
13
13
use url:: Url ;
14
14
15
- use hir:: { Adt , AsAssocItem , AssocItem , AssocItemContainer , HasAttrs , db:: HirDatabase , sym} ;
15
+ use hir:: {
16
+ Adt , AsAssocItem , AssocItem , AssocItemContainer , AttrsWithOwner , HasAttrs , db:: HirDatabase , sym,
17
+ } ;
16
18
use ide_db:: {
17
19
RootDatabase ,
18
20
base_db:: { CrateOrigin , LangCrateOrigin , ReleaseChannel , RootQueryDb } ,
@@ -322,13 +324,7 @@ impl DocCommentToken {
322
324
} ;
323
325
let token_start = t. text_range ( ) . start ( ) ;
324
326
let abs_in_expansion_offset = token_start + relative_comment_offset + descended_prefix_len;
325
-
326
- let ( attributes, def) = if is_inner && node. kind ( ) != SOURCE_FILE {
327
- let parent = node. parent ( ) ?;
328
- doc_attributes ( sema, & parent) . unwrap_or ( doc_attributes ( sema, & parent. parent ( ) ?) ?)
329
- } else {
330
- doc_attributes ( sema, & node) ?
331
- } ;
327
+ let ( attributes, def) = Self :: doc_attributes ( sema, & node, is_inner) ?;
332
328
let ( docs, doc_mapping) = docs_with_rangemap ( sema. db , & attributes) ?;
333
329
let ( in_expansion_range, link, ns, is_inner) =
334
330
extract_definitions_from_docs ( & docs) . into_iter ( ) . find_map ( |( range, link, ns) | {
@@ -343,6 +339,28 @@ impl DocCommentToken {
343
339
cb ( def, node, absolute_range)
344
340
} )
345
341
}
342
+
343
+ /// When we hover a inner doc item, this find a attached definition.
344
+ /// ```
345
+ /// // node == ITEM_LIST
346
+ /// // node.parent == EXPR_BLOCK
347
+ /// // node.parent().parent() == FN
348
+ /// fn f() {
349
+ /// //! [`S$0`]
350
+ /// }
351
+ /// ```
352
+ fn doc_attributes (
353
+ sema : & Semantics < ' _ , RootDatabase > ,
354
+ node : & SyntaxNode ,
355
+ is_inner_doc : bool ,
356
+ ) -> Option < ( AttrsWithOwner , Definition ) > {
357
+ if is_inner_doc && node. kind ( ) != SOURCE_FILE {
358
+ let parent = node. parent ( ) ?;
359
+ doc_attributes ( sema, & parent) . or ( doc_attributes ( sema, & parent. parent ( ) ?) )
360
+ } else {
361
+ doc_attributes ( sema, node)
362
+ }
363
+ }
346
364
}
347
365
348
366
fn broken_link_clone_cb ( link : BrokenLink < ' _ > ) -> Option < ( CowStr < ' _ > , CowStr < ' _ > ) > {
0 commit comments