@@ -5,15 +5,22 @@ import scala.quoted._
5
5
6
6
trait MemberLookup {
7
7
8
+ def memberLookupResult (using Quotes )(
9
+ symbol : quotes.reflect.Symbol ,
10
+ label : String ,
11
+ inheritingParent : Option [quotes.reflect.Symbol ] = None
12
+ ): (quotes.reflect.Symbol , String , Option [quotes.reflect.Symbol ]) =
13
+ (symbol, label, inheritingParent)
14
+
8
15
def lookup (using Quotes , DocContext )(
9
16
query : Query ,
10
17
owner : quotes.reflect.Symbol ,
11
- ): Option [(quotes.reflect.Symbol , String )] = lookupOpt(query, Some (owner))
18
+ ): Option [(quotes.reflect.Symbol , String , Option [quotes.reflect. Symbol ] )] = lookupOpt(query, Some (owner))
12
19
13
20
def lookupOpt (using Quotes , DocContext )(
14
21
query : Query ,
15
22
ownerOpt : Option [quotes.reflect.Symbol ],
16
- ): Option [(quotes.reflect.Symbol , String )] =
23
+ ): Option [(quotes.reflect.Symbol , String , Option [quotes.reflect. Symbol ] )] =
17
24
try
18
25
import quotes .reflect ._
19
26
@@ -26,7 +33,7 @@ trait MemberLookup {
26
33
def nearestMembered (sym : Symbol ): Symbol =
27
34
if sym.isClassDef || sym.flags.is(Flags .Package ) then sym else nearestMembered(sym.owner)
28
35
29
- val res : Option [(Symbol , String )] = {
36
+ val res : Option [(Symbol , String , Option [ Symbol ] )] = {
30
37
def toplevelLookup (querystrings : List [String ]) =
31
38
downwardLookup(querystrings, defn.PredefModule .moduleClass)
32
39
.orElse(downwardLookup(querystrings, defn.ScalaPackage ))
@@ -38,7 +45,7 @@ trait MemberLookup {
38
45
val nearest = nearestMembered(owner)
39
46
val nearestCls = nearestClass(owner)
40
47
val nearestPkg = nearestPackage(owner)
41
- def relativeLookup (querystrings : List [String ], owner : Symbol ): Option [Symbol ] = {
48
+ def relativeLookup (querystrings : List [String ], owner : Symbol ): Option [( Symbol , Option [ Symbol ]) ] = {
42
49
val isMeaningful =
43
50
owner.exists
44
51
// those are just an optimisation, they can be dropped if problems show up
@@ -56,26 +63,27 @@ trait MemberLookup {
56
63
57
64
query match {
58
65
case Query .StrictMemberId (id) =>
59
- localLookup(id, nearest).nextOption.map(_ -> id )
66
+ localLookup(id, nearest).nextOption.map(memberLookupResult(_, id) )
60
67
case Query .QualifiedId (Query .Qual .This , _, rest) =>
61
- downwardLookup(rest.asList, nearestCls).map(_ -> rest.join)
68
+ downwardLookup(rest.asList, nearestCls).map(memberLookupResult(_, rest.join, _) )
62
69
case Query .QualifiedId (Query .Qual .Package , _, rest) =>
63
- downwardLookup(rest.asList, nearestPkg).map(_ -> rest.join)
70
+ downwardLookup(rest.asList, nearestPkg).map(memberLookupResult(_, rest.join, _) )
64
71
case query =>
65
72
val ql = query.asList
66
73
toplevelLookup(ql)
67
74
.orElse(relativeLookup(ql, nearest))
68
- .map(_ -> query.join)
75
+ .map(memberLookupResult(_, query.join, _) )
69
76
}
70
77
71
78
case None =>
72
- toplevelLookup(query.asList).map(_ -> query.join)
79
+ toplevelLookup(query.asList).map(memberLookupResult(_, query.join, _) )
73
80
}
74
81
}
75
82
76
83
// println(s"looked up `$query` in ${owner.show}[${owner.flags.show}] as ${res.map(_.show)}")
77
84
78
85
res
86
+
79
87
catch
80
88
case e : Exception =>
81
89
// TODO (https://github.com/lampepfl/scala3doc/issues/238): proper reporting
@@ -169,11 +177,13 @@ trait MemberLookup {
169
177
}
170
178
}
171
179
172
- private def downwardLookup (using Quotes )(query : List [String ], owner : quotes.reflect.Symbol ): Option [quotes.reflect.Symbol ] = {
180
+ private def downwardLookup (using Quotes )(
181
+ query : List [String ], owner : quotes.reflect.Symbol
182
+ ): Option [(quotes.reflect.Symbol , Option [quotes.reflect.Symbol ])] = {
173
183
import quotes .reflect ._
174
184
query match {
175
185
case Nil => None
176
- case q :: Nil => localLookup(q, owner).nextOption
186
+ case q :: Nil => localLookup(q, owner).nextOption.map((_, None ))
177
187
case q :: qs =>
178
188
val lookedUp =
179
189
localLookup(q, owner).toSeq
@@ -191,8 +201,18 @@ trait MemberLookup {
191
201
else if s.flags.is(Flags .Module ) then tm = Some (s)
192
202
else if s.isClassDef || s.isTypeDef then tp = Some (s)
193
203
}
204
+
205
+ def downwardLookUpForInheritedMembers (qs : List [String ], owner : Symbol ): Option [(Symbol , Option [Symbol ])] =
206
+ downwardLookup(qs, owner).orElse(owner.memberMethod(qs.head).headOption.map((_, Some (owner)))).orElse {
207
+ val symbol = owner.memberType(qs.head)
208
+ Option .when(symbol != dotty.tools.dotc.core.Symbols .NoSymbol )(symbol).map((_, Some (owner)))
209
+ }.orElse {
210
+ val symbol = owner.memberField(qs.head)
211
+ Option .when(symbol != dotty.tools.dotc.core.Symbols .NoSymbol )(symbol).map((_, Some (owner)))
212
+ }
213
+
194
214
pk.flatMap(downwardLookup(qs, _))
195
- .orElse(tp.flatMap(downwardLookup (qs, _)))
215
+ .orElse(tp.flatMap(downwardLookUpForInheritedMembers (qs, _)))
196
216
.orElse(tm.flatMap(downwardLookup(qs, _)))
197
217
}
198
218
}
0 commit comments