Skip to content

Commit d57e855

Browse files
committed
add companionClass and companionModule to tastyreflect + use them to select correct symbol name
1 parent 50f07d5 commit d57e855

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
3030

3131
def owner(implicit ctx: Context): Symbol = symbol.owner
3232

33+
def companionModule(implicit ctx: Context): Symbol = symbol.companionModule
34+
35+
def companionClass(implicit ctx: Context): Symbol = symbol.companionClass
36+
3337
def localContext(implicit ctx: Context): Context = {
3438
if (symbol.exists) ctx.withOwner(symbol)
3539
else ctx

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ trait SymbolOps extends Core {
2626
/** The full name of this symbol up to the root package. */
2727
def fullName(implicit ctx: Context): String
2828

29+
30+
def companionModule(implicit ctx: Context): Symbol
31+
32+
def companionClass(implicit ctx: Context): Symbol
33+
2934
def pos(implicit ctx: Context): Position
3035

3136
def localContext(implicit ctx: Context): Context

semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class SemanticdbConsumer extends TastyConsumer {
7070
case _ => false
7171
}
7272

73+
def isObject: Boolean = symbol.flags.isObject
74+
7375
def isTrait: Boolean = symbol.flags.isTrait
7476

7577
def isValueParameter: Boolean = symbol.flags.isParam
@@ -105,13 +107,17 @@ class SemanticdbConsumer extends TastyConsumer {
105107
val next_atom =
106108
if (symbol.isPackage) {
107109
d.Package(symbol.name)
108-
} else if (symbol.isTypeParameter) {
109-
d.TypeParameter(symbol.name)
110+
} else if (symbol.isObject) {
111+
d.Term(symbol.companionModule.name)
110112
} else if (symbol.isMethod) {
111113
d.Method(symbol.name, disimbiguate(previous_symbol + symbol.name))
112114
} else if (symbol.isValueParameter) {
113115
d.Parameter(symbol.name)
116+
} else if (symbol.isTypeParameter) {
117+
d.TypeParameter(symbol.name)
114118
} else if (symbol.isType || symbol.isTrait) {
119+
//println(symbol.name, symbol.companionClass.name, symbol.companionModule.name, symbol.flags.toString)
120+
115121
d.Type(symbol.name)
116122
} else {
117123
d.Term(symbol.name)

0 commit comments

Comments
 (0)