@@ -12,9 +12,9 @@ use hir_ty::db::HirDatabase;
12
12
use syntax:: { ast, AstNode } ;
13
13
14
14
use crate :: {
15
- Adt , AssocItem , Const , ConstParam , Enum , Field , Function , GenericParam , Impl , LifetimeParam ,
16
- Macro , Module , ModuleDef , Static , Struct , Trait , TraitAlias , TypeAlias , TypeParam , Union ,
17
- Variant ,
15
+ Adt , AssocItem , Const , ConstParam , Enum , ExternCrateDecl , Field , Function , GenericParam , Impl ,
16
+ LifetimeParam , Macro , Module , ModuleDef , Static , Struct , Trait , TraitAlias , TypeAlias ,
17
+ TypeParam , Union , Variant ,
18
18
} ;
19
19
20
20
pub trait HasAttrs {
@@ -120,6 +120,39 @@ impl HasAttrs for AssocItem {
120
120
}
121
121
}
122
122
123
+ impl HasAttrs for ExternCrateDecl {
124
+ fn attrs ( self , db : & dyn HirDatabase ) -> AttrsWithOwner {
125
+ let def = AttrDefId :: ExternCrateId ( self . into ( ) ) ;
126
+ db. attrs_with_owner ( def)
127
+ }
128
+ fn docs ( self , db : & dyn HirDatabase ) -> Option < Documentation > {
129
+ let crate_docs = self . resolved_crate ( db) . root_module ( ) . attrs ( db) . docs ( ) . map ( String :: from) ;
130
+ let def = AttrDefId :: ExternCrateId ( self . into ( ) ) ;
131
+ let decl_docs = db. attrs ( def) . docs ( ) . map ( String :: from) ;
132
+ match ( decl_docs, crate_docs) {
133
+ ( None , None ) => None ,
134
+ ( Some ( decl_docs) , None ) => Some ( decl_docs) ,
135
+ ( None , Some ( crate_docs) ) => Some ( crate_docs) ,
136
+ ( Some ( mut decl_docs) , Some ( crate_docs) ) => {
137
+ decl_docs. push ( '\n' ) ;
138
+ decl_docs. push ( '\n' ) ;
139
+ decl_docs += & crate_docs;
140
+ Some ( decl_docs)
141
+ }
142
+ }
143
+ . map ( Documentation :: new)
144
+ }
145
+ fn resolve_doc_path (
146
+ self ,
147
+ db : & dyn HirDatabase ,
148
+ link : & str ,
149
+ ns : Option < Namespace > ,
150
+ ) -> Option < ModuleDef > {
151
+ let def = AttrDefId :: ExternCrateId ( self . into ( ) ) ;
152
+ resolve_doc_path ( db, def, link, ns) . map ( ModuleDef :: from)
153
+ }
154
+ }
155
+
123
156
/// Resolves the item `link` points to in the scope of `def`.
124
157
fn resolve_doc_path (
125
158
db : & dyn HirDatabase ,
0 commit comments