@@ -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
@@ -165,13 +172,15 @@ trait MemberLookup {
165172 }
166173 }
167174
168- private def downwardLookup (using Quotes )(query : List [String ], owner : quotes.reflect.Symbol ): Option [quotes.reflect.Symbol ] = {
175+ private def downwardLookup (using Quotes )(
176+ query : List [String ], owner : quotes.reflect.Symbol
177+ ): Option [(quotes.reflect.Symbol , Option [quotes.reflect.Symbol ])] = {
169178 import quotes .reflect ._
170179 query match {
171180 case Nil => None
172181 case q :: Nil =>
173182 val sel = MemberLookup .Selector .fromString(q)
174- sel.kind match {
183+ val res = sel.kind match {
175184 case MemberLookup .SelectorKind .NoForce =>
176185 val lookedUp = localLookup(sel, owner).toSeq
177186 // note: those flag lookups are necessary b/c for objects we return their classes
@@ -180,7 +189,16 @@ trait MemberLookup {
180189 )
181190 case _ =>
182191 localLookup(sel, owner).nextOption
183-
192+ }
193+ res match {
194+ case None => None
195+ case Some (sym) =>
196+ val externalOwner : Option [quotes.reflect.Symbol ] =
197+ if owner eq sym.owner then None
198+ else if owner.flags.is(Flags .Module ) then Some (owner.moduleClass)
199+ else if owner.isClassDef then Some (owner)
200+ else None
201+ Some (sym -> externalOwner)
184202 }
185203 case q :: qs =>
186204 val sel = MemberLookup .Selector .fromString(q)
0 commit comments