@@ -5,15 +5,22 @@ import scala.quoted._
55
66trait MemberLookup {
77
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+
815 def lookup (using Quotes , DocContext )(
916 query : Query ,
1017 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))
1219
1320 def lookupOpt (using Quotes , DocContext )(
1421 query : Query ,
1522 ownerOpt : Option [quotes.reflect.Symbol ],
16- ): Option [(quotes.reflect.Symbol , String )] =
23+ ): Option [(quotes.reflect.Symbol , String , Option [quotes.reflect. Symbol ] )] =
1724 try
1825 import quotes .reflect ._
1926
@@ -26,7 +33,7 @@ trait MemberLookup {
2633 def nearestMembered (sym : Symbol ): Symbol =
2734 if sym.isClassDef || sym.flags.is(Flags .Package ) then sym else nearestMembered(sym.owner)
2835
29- val res : Option [(Symbol , String )] = {
36+ val res : Option [(Symbol , String , Option [ Symbol ] )] = {
3037 def toplevelLookup (querystrings : List [String ]) =
3138 downwardLookup(querystrings, defn.PredefModule .moduleClass)
3239 .orElse(downwardLookup(querystrings, defn.ScalaPackage ))
@@ -38,7 +45,7 @@ trait MemberLookup {
3845 val nearest = nearestMembered(owner)
3946 val nearestCls = nearestClass(owner)
4047 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 ]) ] = {
4249 val isMeaningful =
4350 owner.exists
4451 // those are just an optimisation, they can be dropped if problems show up
@@ -56,20 +63,20 @@ trait MemberLookup {
5663
5764 query match {
5865 case Query .StrictMemberId (id) =>
59- downwardLookup(List (id), nearest).map(_ -> id )
66+ downwardLookup(List (id), nearest).map(memberLookupResult(_, id, _) )
6067 case Query .QualifiedId (Query .Qual .This , _, rest) =>
61- downwardLookup(rest.asList, nearestCls).map(_ -> rest.join)
68+ downwardLookup(rest.asList, nearestCls).map(memberLookupResult(_, rest.join, _) )
6269 case Query .QualifiedId (Query .Qual .Package , _, rest) =>
63- downwardLookup(rest.asList, nearestPkg).map(_ -> rest.join)
70+ downwardLookup(rest.asList, nearestPkg).map(memberLookupResult(_, rest.join, _) )
6471 case query =>
6572 val ql = query.asList
6673 toplevelLookup(ql)
6774 .orElse(relativeLookup(ql, nearest))
68- .map(_ -> query.join)
75+ .map(memberLookupResult(_, query.join, _) )
6976 }
7077
7178 case None =>
72- toplevelLookup(query.asList).map(_ -> query.join)
79+ toplevelLookup(query.asList).map(memberLookupResult(_, query.join, _) )
7380 }
7481 }
7582
@@ -163,13 +170,15 @@ trait MemberLookup {
163170 }
164171 }
165172
166- private def downwardLookup (using Quotes )(query : List [String ], owner : quotes.reflect.Symbol ): Option [quotes.reflect.Symbol ] = {
173+ private def downwardLookup (using Quotes )(
174+ query : List [String ], owner : quotes.reflect.Symbol
175+ ): Option [(quotes.reflect.Symbol , Option [quotes.reflect.Symbol ])] = {
167176 import quotes .reflect ._
168177 query match {
169178 case Nil => None
170179 case q :: Nil =>
171180 val sel = MemberLookup .Selector .fromString(q)
172- sel.kind match {
181+ val res = sel.kind match {
173182 case MemberLookup .SelectorKind .NoForce =>
174183 val lookedUp = localLookup(sel, owner).toSeq
175184 // note: those flag lookups are necessary b/c for objects we return their classes
@@ -178,7 +187,16 @@ trait MemberLookup {
178187 )
179188 case _ =>
180189 localLookup(sel, owner).nextOption
181-
190+ }
191+ res match {
192+ case None => None
193+ case Some (sym) =>
194+ val externalOwner : Option [quotes.reflect.Symbol ] =
195+ if owner eq sym.owner then None
196+ else if owner.flags.is(Flags .Module ) then Some (owner.moduleClass)
197+ else if owner.isClassDef then Some (owner)
198+ else None
199+ Some (sym -> externalOwner)
182200 }
183201 case q :: qs =>
184202 val sel = MemberLookup .Selector .fromString(q)
0 commit comments