Skip to content

Commit 08aae95

Browse files
committed
Par back sourceSymbol usage, to keep some non-source
Given: class Foo(name: String, age: Int) case class Person(name: String) Is the Foo constructor symbol synthetic? Being the primary constructor, sourceSymbol considers it should be substituted for the Foo class symbol. Similarly, the Person apply method symbol is replaced by the class symbol for Person (via the Person module class). Doing so leads the presentation compiler to show details about the class, rather than the constructor or the apply method intially targeted.
1 parent 4fdd03a commit 08aae95

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ object Symbols extends SymUtils {
325325

326326
/** A symbol related to `sym` that is defined in source code.
327327
*
328-
* @see enclosingSourceSymbols
328+
* @see [[interactive.Interactive.enclosingSourceSymbols]]
329329
*/
330330
@annotation.tailrec final def sourceSymbol(using Context): Symbol =
331331
if (!denot.exists)

presentation-compiler/src/main/dotty/tools/pc/MetalsInteractive.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ object MetalsInteractive:
229229
end if
230230
case Nil => Nil
231231
end go
232-
go(path).map((sym, tp) => (sym.sourceSymbol, tp))
232+
go(path).map { (sym, tp) =>
233+
if sym.is(Synthetic) && sym.name == StdNames.nme.apply then
234+
(sym, tp) // return synthetic apply, rather than the apply's owner
235+
else if sym.isClassConstructor && sym.isPrimaryConstructor then
236+
(sym, tp) // return the class constructor, rather than the class (so skip trait constructors)
237+
else
238+
(sym.sourceSymbol, tp)
239+
}
233240
end enclosingSymbolsWithExpressionType
234241

235242
import dotty.tools.pc.utils.MtagsEnrichments.*

0 commit comments

Comments
 (0)