@@ -6,33 +6,22 @@ use hir_def::{
6
6
path:: { ModPath , Path } ,
7
7
per_ns:: Namespace ,
8
8
resolver:: { HasResolver , Resolver , TypeNs } ,
9
- AssocItemId , AttrDefId , GenericParamId , ModuleDefId ,
9
+ AssocItemId , AttrDefId , ModuleDefId ,
10
10
} ;
11
11
use hir_expand:: { hygiene:: Hygiene , name:: Name } ;
12
12
use hir_ty:: db:: HirDatabase ;
13
13
use syntax:: { ast, AstNode } ;
14
14
15
15
use crate :: {
16
- Adt , AsAssocItem , AssocItem , BuiltinType , Const , ConstParam , Enum , ExternCrateDecl , Field ,
17
- Function , GenericParam , Impl , LifetimeParam , Macro , Module , ModuleDef , Static , Struct , Trait ,
18
- TraitAlias , TypeAlias , TypeParam , Union , Variant , VariantDef ,
16
+ Adt , AsAssocItem , AssocItem , BuiltinType , Const , ConstParam , DocLinkDef , Enum , ExternCrateDecl ,
17
+ Field , Function , GenericParam , Impl , LifetimeParam , Macro , Module , ModuleDef , Static , Struct ,
18
+ Trait , TraitAlias , TypeAlias , TypeParam , Union , Variant , VariantDef ,
19
19
} ;
20
20
21
21
pub trait HasAttrs {
22
22
fn attrs ( self , db : & dyn HirDatabase ) -> AttrsWithOwner ;
23
- fn resolve_doc_path (
24
- self ,
25
- db : & dyn HirDatabase ,
26
- link : & str ,
27
- ns : Option < Namespace > ,
28
- ) -> Option < DocLinkDef > ;
29
- }
30
-
31
- /// Subset of `ide_db::Definition` that doc links can resolve to.
32
- pub enum DocLinkDef {
33
- ModuleDef ( ModuleDef ) ,
34
- Field ( Field ) ,
35
- SelfType ( Trait ) ,
23
+ #[ doc( hidden) ]
24
+ fn attr_id ( self ) -> AttrDefId ;
36
25
}
37
26
38
27
macro_rules! impl_has_attrs {
@@ -42,14 +31,8 @@ macro_rules! impl_has_attrs {
42
31
let def = AttrDefId :: $def_id( self . into( ) ) ;
43
32
db. attrs_with_owner( def)
44
33
}
45
- fn resolve_doc_path(
46
- self ,
47
- db: & dyn HirDatabase ,
48
- link: & str ,
49
- ns: Option <Namespace >
50
- ) -> Option <DocLinkDef > {
51
- let def = AttrDefId :: $def_id( self . into( ) ) ;
52
- resolve_doc_path( db, def, link, ns)
34
+ fn attr_id( self ) -> AttrDefId {
35
+ AttrDefId :: $def_id( self . into( ) )
53
36
}
54
37
}
55
38
) * } ;
@@ -69,6 +52,7 @@ impl_has_attrs![
69
52
( Module , ModuleId ) ,
70
53
( GenericParam , GenericParamId ) ,
71
54
( Impl , ImplId ) ,
55
+ ( ExternCrateDecl , ExternCrateId ) ,
72
56
] ;
73
57
74
58
macro_rules! impl_has_attrs_enum {
@@ -77,13 +61,8 @@ macro_rules! impl_has_attrs_enum {
77
61
fn attrs( self , db: & dyn HirDatabase ) -> AttrsWithOwner {
78
62
$enum:: $variant( self ) . attrs( db)
79
63
}
80
- fn resolve_doc_path(
81
- self ,
82
- db: & dyn HirDatabase ,
83
- link: & str ,
84
- ns: Option <Namespace >
85
- ) -> Option <DocLinkDef > {
86
- $enum:: $variant( self ) . resolve_doc_path( db, link, ns)
64
+ fn attr_id( self ) -> AttrDefId {
65
+ $enum:: $variant( self ) . attr_id( )
87
66
}
88
67
}
89
68
) * } ;
@@ -100,45 +79,35 @@ impl HasAttrs for AssocItem {
100
79
AssocItem :: TypeAlias ( it) => it. attrs ( db) ,
101
80
}
102
81
}
103
-
104
- fn resolve_doc_path (
105
- self ,
106
- db : & dyn HirDatabase ,
107
- link : & str ,
108
- ns : Option < Namespace > ,
109
- ) -> Option < DocLinkDef > {
82
+ fn attr_id ( self ) -> AttrDefId {
110
83
match self {
111
- AssocItem :: Function ( it) => it. resolve_doc_path ( db , link , ns ) ,
112
- AssocItem :: Const ( it) => it. resolve_doc_path ( db , link , ns ) ,
113
- AssocItem :: TypeAlias ( it) => it. resolve_doc_path ( db , link , ns ) ,
84
+ AssocItem :: Function ( it) => it. attr_id ( ) ,
85
+ AssocItem :: Const ( it) => it. attr_id ( ) ,
86
+ AssocItem :: TypeAlias ( it) => it. attr_id ( ) ,
114
87
}
115
88
}
116
89
}
117
90
118
- impl HasAttrs for ExternCrateDecl {
119
- fn attrs ( self , db : & dyn HirDatabase ) -> AttrsWithOwner {
120
- let def = AttrDefId :: ExternCrateId ( self . into ( ) ) ;
121
- db. attrs_with_owner ( def)
122
- }
123
- fn resolve_doc_path (
124
- self ,
125
- db : & dyn HirDatabase ,
126
- link : & str ,
127
- ns : Option < Namespace > ,
128
- ) -> Option < DocLinkDef > {
129
- let def = AttrDefId :: ExternCrateId ( self . into ( ) ) ;
130
- resolve_doc_path ( db, def, link, ns)
131
- }
91
+ /// Resolves the item `link` points to in the scope of `def`.
92
+ pub fn resolve_doc_path_on (
93
+ db : & dyn HirDatabase ,
94
+ def : impl HasAttrs ,
95
+ link : & str ,
96
+ ns : Option < Namespace > ,
97
+ ) -> Option < DocLinkDef > {
98
+ // AttrDefId::FieldId(it) => it.parent.resolver(db.upcast()),
99
+ // AttrDefId::EnumVariantId(it) => it.parent.resolver(db.upcast()),
100
+
101
+ resolve_doc_path_on_ ( db, link, def. attr_id ( ) , ns)
132
102
}
133
103
134
- /// Resolves the item `link` points to in the scope of `def`.
135
- fn resolve_doc_path (
104
+ fn resolve_doc_path_on_ (
136
105
db : & dyn HirDatabase ,
137
- def : AttrDefId ,
138
106
link : & str ,
107
+ attr_id : AttrDefId ,
139
108
ns : Option < Namespace > ,
140
109
) -> Option < DocLinkDef > {
141
- let resolver = match def {
110
+ let resolver = match attr_id {
142
111
AttrDefId :: ModuleId ( it) => it. resolver ( db. upcast ( ) ) ,
143
112
AttrDefId :: FieldId ( it) => it. parent . resolver ( db. upcast ( ) ) ,
144
113
AttrDefId :: AdtId ( it) => it. resolver ( db. upcast ( ) ) ,
@@ -154,12 +123,7 @@ fn resolve_doc_path(
154
123
AttrDefId :: UseId ( it) => it. resolver ( db. upcast ( ) ) ,
155
124
AttrDefId :: MacroId ( it) => it. resolver ( db. upcast ( ) ) ,
156
125
AttrDefId :: ExternCrateId ( it) => it. resolver ( db. upcast ( ) ) ,
157
- AttrDefId :: GenericParamId ( it) => match it {
158
- GenericParamId :: TypeParamId ( it) => it. parent ( ) ,
159
- GenericParamId :: ConstParamId ( it) => it. parent ( ) ,
160
- GenericParamId :: LifetimeParamId ( it) => it. parent ,
161
- }
162
- . resolver ( db. upcast ( ) ) ,
126
+ AttrDefId :: GenericParamId ( _) => return None ,
163
127
} ;
164
128
165
129
let mut modpath = modpath_from_str ( db, link) ?;
0 commit comments