1
1
//! FIXME: write short doc here
2
2
3
3
use either:: Either ;
4
- use hir:: { AssocItem , FieldSource , HasSource , InFile , ModuleSource } ;
4
+ use hir:: {
5
+ AssocItem , Documentation , FieldSource , HasAttrs , HasSource , HirFileId , InFile , ModuleSource ,
6
+ } ;
5
7
use ide_db:: base_db:: { FileId , SourceDatabase } ;
6
8
use ide_db:: { defs:: Definition , RootDatabase } ;
7
9
use syntax:: {
8
- ast:: { self , DocCommentsOwner , NameOwner } ,
10
+ ast:: { self , NameOwner } ,
9
11
match_ast, AstNode , SmolStr ,
10
12
SyntaxKind :: { self , IDENT_PAT , TYPE_PARAM } ,
11
13
TextRange ,
@@ -43,7 +45,7 @@ pub struct NavigationTarget {
43
45
pub kind : SyntaxKind ,
44
46
pub container_name : Option < SmolStr > ,
45
47
pub description : Option < String > ,
46
- pub docs : Option < String > ,
48
+ pub docs : Option < Documentation > ,
47
49
}
48
50
49
51
pub ( crate ) trait ToNav {
@@ -71,7 +73,7 @@ impl NavigationTarget {
71
73
frange. range ,
72
74
src. value . syntax ( ) . kind ( ) ,
73
75
) ;
74
- res. docs = src . value . doc_comment_text ( ) ;
76
+ res. docs = module . attrs ( db ) . docs ( ) ;
75
77
res. description = src. value . short_label ( ) ;
76
78
return res;
77
79
}
@@ -214,14 +216,14 @@ impl ToNavFromAst for hir::Trait {}
214
216
215
217
impl < D > ToNav for D
216
218
where
217
- D : HasSource + ToNavFromAst + Copy ,
218
- D :: Ast : ast:: DocCommentsOwner + ast :: NameOwner + ShortLabel ,
219
+ D : HasSource + ToNavFromAst + Copy + HasAttrs ,
220
+ D :: Ast : ast:: NameOwner + ShortLabel ,
219
221
{
220
222
fn to_nav ( & self , db : & RootDatabase ) -> NavigationTarget {
221
223
let src = self . source ( db) ;
222
224
let mut res =
223
225
NavigationTarget :: from_named ( db, src. as_ref ( ) . map ( |it| it as & dyn ast:: NameOwner ) ) ;
224
- res. docs = src . value . doc_comment_text ( ) ;
226
+ res. docs = self . docs ( db ) ;
225
227
res. description = src. value . short_label ( ) ;
226
228
res
227
229
}
@@ -274,7 +276,7 @@ impl ToNav for hir::Field {
274
276
match & src. value {
275
277
FieldSource :: Named ( it) => {
276
278
let mut res = NavigationTarget :: from_named ( db, src. with_value ( it) ) ;
277
- res. docs = it . doc_comment_text ( ) ;
279
+ res. docs = self . docs ( db ) ;
278
280
res. description = it. short_label ( ) ;
279
281
res
280
282
}
@@ -298,7 +300,7 @@ impl ToNav for hir::MacroDef {
298
300
log:: debug!( "nav target {:#?}" , src. value. syntax( ) ) ;
299
301
let mut res =
300
302
NavigationTarget :: from_named ( db, src. as_ref ( ) . map ( |it| it as & dyn ast:: NameOwner ) ) ;
301
- res. docs = src . value . doc_comment_text ( ) ;
303
+ res. docs = self . docs ( db ) ;
302
304
res
303
305
}
304
306
}
@@ -374,26 +376,28 @@ impl ToNav for hir::TypeParam {
374
376
}
375
377
}
376
378
377
- pub ( crate ) fn docs_from_symbol ( db : & RootDatabase , symbol : & FileSymbol ) -> Option < String > {
379
+ pub ( crate ) fn docs_from_symbol ( db : & RootDatabase , symbol : & FileSymbol ) -> Option < Documentation > {
378
380
let parse = db. parse ( symbol. file_id ) ;
379
381
let node = symbol. ptr . to_node ( parse. tree ( ) . syntax ( ) ) ;
382
+ let file_id = HirFileId :: from ( symbol. file_id ) ;
380
383
381
- match_ast ! {
384
+ let it = match_ast ! {
382
385
match node {
383
- ast:: Fn ( it) => it . doc_comment_text ( ) ,
384
- ast:: Struct ( it) => it . doc_comment_text ( ) ,
385
- ast:: Enum ( it) => it . doc_comment_text ( ) ,
386
- ast:: Trait ( it) => it . doc_comment_text ( ) ,
387
- ast:: Module ( it) => it . doc_comment_text ( ) ,
388
- ast:: TypeAlias ( it) => it . doc_comment_text ( ) ,
389
- ast:: Const ( it) => it . doc_comment_text ( ) ,
390
- ast:: Static ( it) => it . doc_comment_text ( ) ,
391
- ast:: RecordField ( it) => it . doc_comment_text ( ) ,
392
- ast:: Variant ( it) => it . doc_comment_text ( ) ,
393
- ast:: MacroCall ( it) => it . doc_comment_text ( ) ,
394
- _ => None ,
386
+ ast:: Fn ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
387
+ ast:: Struct ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
388
+ ast:: Enum ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
389
+ ast:: Trait ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
390
+ ast:: Module ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
391
+ ast:: TypeAlias ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
392
+ ast:: Const ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
393
+ ast:: Static ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
394
+ ast:: RecordField ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
395
+ ast:: Variant ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
396
+ ast:: MacroCall ( it) => hir :: Attrs :: from_attrs_owner ( db , InFile :: new ( file_id , & it ) ) ,
397
+ _ => return None ,
395
398
}
396
- }
399
+ } ;
400
+ it. docs ( )
397
401
}
398
402
399
403
/// Get a description of a symbol.
0 commit comments