Skip to content

Commit ba278fa

Browse files
committed
Ignore noise in templates and children of synthetics
1 parent 3bc85d7 commit ba278fa

14 files changed

+158
-69
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ class ExtractSemanticDB extends Phase {
9191
addDescriptor(sym.sourceModule)
9292
else if sym.is(TypeParam) then
9393
b.append('['); addName(sym.name); b.append(']')
94-
else if sym.is(Param) || sym.is(ParamAccessor) then
94+
else if sym.is(Param) then
9595
b.append('('); addName(sym.name); b.append(')')
9696
else
9797
addName(sym.name)
9898
if sym.is(Package) then b.append('/')
9999
else if sym.isType then b.append('#')
100-
else if sym.is(Method) && (!sym.is(Accessor) || sym.is(Mutable)) then
100+
else if sym.is(Method) || (sym.isOneOf(Accessor | Local) && sym.is(Mutable)) then
101101
b.append('('); addOverloadIdx(sym); b.append(").")
102102
else b.append('.')
103103

@@ -152,11 +152,14 @@ class ExtractSemanticDB extends Phase {
152152
private def excludeDef(sym: Symbol)(given Context): Boolean =
153153
!sym.exists
154154
|| sym.isLocalDummy
155-
|| sym.is(Synthetic)
156-
|| sym.isAnonymousClass
155+
|| sym.is(Synthetic) || (sym.owner.is(Synthetic) && !sym.isAllOf(EnumCase))
156+
|| sym.isAnonymous
157+
|| sym.isPrimaryConstructor && excludeDef(sym.owner)
158+
159+
private def (sym: Symbol) isAnonymous(given Context): Boolean =
160+
sym.isAnonymousClass
157161
|| sym.isAnonymousModuleVal
158162
|| sym.isAnonymousFunction
159-
|| sym.isPrimaryConstructor && excludeDef(sym.owner)
160163

161164
/** Uses of this symbol where the reference has given span should be excluded from semanticdb */
162165
private def excludeUse(sym: Symbol, span: Span)(given Context): Boolean =
@@ -196,6 +199,24 @@ class ExtractSemanticDB extends Phase {
196199
if !excludeDef(tree.symbol) && tree.span.start != tree.span.end =>
197200
registerDefinition(tree.symbol, tree.nameSpan)
198201
traverseChildren(tree)
202+
case tree: (ValDef | DefDef | TypeDef) if tree.symbol.is(Synthetic, butNot=Module) && !tree.symbol.isAnonymous => // skip
203+
case tree: Template =>
204+
for
205+
vparams <- tree.constr.vparamss
206+
vparam <- vparams
207+
do
208+
traverse(vparam.tpt) // the accessor symbol is traversed in the body
209+
for parent <- tree.parentsOrDerived do
210+
if
211+
parent.symbol != defn.ObjectClass.primaryConstructor
212+
&& parent.tpe.dealias != defn.SerializableType
213+
&& parent.symbol != defn.ProductClass
214+
then
215+
traverse(parent)
216+
val selfSpan = tree.self.span
217+
if selfSpan.exists && selfSpan.start != selfSpan.end then
218+
traverse(tree.self)
219+
tree.body.foreach(traverse)
199220
case tree: Ident =>
200221
if tree.name != nme.WILDCARD && !excludeUse(tree.symbol, tree.span) then
201222
registerUse(tree.symbol, tree.span)
@@ -211,12 +232,13 @@ class ExtractSemanticDB extends Phase {
211232
registerUse(tree.symbol, Span(start max limit, end))
212233
traverseChildren(tree)
213234
case tree: Import =>
214-
for sel <- tree.selectors do
215-
val imported = sel.imported.name
216-
if imported != nme.WILDCARD then
217-
for alt <- tree.expr.tpe.member(imported).alternatives do
218-
registerUse(alt.symbol, sel.imported.span)
219-
registerPath(tree.expr)
235+
if tree.span.exists && tree.span.start != tree.span.end then
236+
for sel <- tree.selectors do
237+
val imported = sel.imported.name
238+
if imported != nme.WILDCARD then
239+
for alt <- tree.expr.tpe.member(imported).alternatives do
240+
registerUse(alt.symbol, sel.imported.span)
241+
registerPath(tree.expr)
220242
case tree: Inlined =>
221243
traverse(tree.call)
222244
case tree: PackageDef => tree.stats.foreach(traverse)

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SemanticdbTests {
6464
val args = Array(
6565
"-Ysemanticdb",
6666
"-d", target.toString,
67+
// "-Ydebug",
6768
// "-Xprint:extractSemanticDB",
6869
"-sourceroot", src.toString,
6970
"-usejavacp",

tests/semanticdb/Access.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package example
22

3-
class /*=>>java.lang.Object#`<init>`().*/Access/*<<=example.Access#*/ {
3+
class Access/*<<=example.Access#*/ {
44
private def m1/*<<=example.Access#m1().*/ = ???/*=>>scala.Predef.`???`().*/
55
private[this] def m2/*<<=example.Access#m2().*/ = ???/*=>>scala.Predef.`???`().*/
66
private[Access] def m3/*<<=example.Access#m3().*/ = ???/*=>>scala.Predef.`???`().*/

tests/semanticdb/Advanced.expect.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import scala.language/*=>>scalaShadowing.language.*/.reflectiveCalls/*=>>scalaSh
55

66
import scala.reflect/*=>>scala.reflect.*/.Selectable/*=>>scala.reflect.Selectable.*/.reflectiveSelectable/*=>>scala.reflect.Selectable.reflectiveSelectable().*/
77

8-
class /*=>>java.lang.Object#`<init>`().*/C/*<<=advanced.C#*/[T] {
9-
/*<<=advanced.C#`<init>`().*//*<<=advanced.C#`<init>`().[T]*//*<<=advanced.C#[T]*/ def t/*<<=advanced.C#t().*/: T/*=>>advanced.C#[T]*/ = ???/*=>>scala.Predef.`???`().*/
8+
class C/*<<=advanced.C#*/[T/*<<=advanced.C#[T]*/] {
9+
def t/*<<=advanced.C#t().*/: T/*=>>advanced.C#[T]*/ = ???/*=>>scala.Predef.`???`().*/
1010
}
1111

12-
class /*=>>java.lang.Object#`<init>`().*/Structural/*<<=advanced.Structural#*/ {
12+
class Structural/*<<=advanced.Structural#*/ {
1313
def s1/*<<=advanced.Structural#s1().*/: { val x/*<<=local0*/: Int/*=>>scala.Int#*/ } = ???/*=>>scala.Predef.`???`().*/
14-
def s2/*<<=advanced.Structural#s2().*/: { val x/*<<=local1*/: Int/*=>>scala.Int#*/ } = /*=>>java.lang.Object#`<init>`().*/new { val x/*<<=local2*/: Int/*=>>scala.Int#*/ = ???/*=>>scala.Predef.`???`().*/ }
15-
def s3/*<<=advanced.Structural#s3().*/: { def m/*<<=local3*/(x/*<<=local4*/: Int/*=>>scala.Int#*/): Int/*=>>scala.Int#*/ } = /*=>>java.lang.Object#`<init>`().*/new { def m/*<<=local5*/(x/*<<=local6*/: Int/*=>>scala.Int#*/): Int/*=>>scala.Int#*/ = ???/*=>>scala.Predef.`???`().*/ }
14+
def s2/*<<=advanced.Structural#s2().*/: { val x/*<<=local1*/: Int/*=>>scala.Int#*/ } = new { val x/*<<=local2*/: Int/*=>>scala.Int#*/ = ???/*=>>scala.Predef.`???`().*/ }
15+
def s3/*<<=advanced.Structural#s3().*/: { def m/*<<=local3*/(x/*<<=local4*/: Int/*=>>scala.Int#*/): Int/*=>>scala.Int#*/ } = new { def m/*<<=local5*/(x/*<<=local6*/: Int/*=>>scala.Int#*/): Int/*=>>scala.Int#*/ = ???/*=>>scala.Predef.`???`().*/ }
1616
}
1717

18-
class /*=>>java.lang.Object#`<init>`().*/Wildcards/*<<=advanced.Wildcards#*/ {
18+
class Wildcards/*<<=advanced.Wildcards#*/ {
1919
def e1/*<<=advanced.Wildcards#e1().*/: List/*=>>scala.package.List#*/[_] = ???/*=>>scala.Predef.`???`().*/
2020
}
2121

22-
object /*=>>java.lang.Object#`<init>`().*/Test/*<<=advanced.Test.*/ {
23-
/*=>>scala.package.Serializable#*//*=>>scala.*//*=>>_root_*//*=>>advanced.Test.*/val s/*<<=advanced.Test.s.*/ = new Structural/*=>>advanced.Structural#*//*=>>advanced.Structural#`<init>`().*/
22+
object Test/*<<=advanced.Test.*/ {
23+
val s/*<<=advanced.Test.s.*/ = new Structural/*=>>advanced.Structural#*//*=>>advanced.Structural#`<init>`().*/
2424
val s1/*<<=advanced.Test.s1.*/ = s/*=>>advanced.Test.s.*/.s1/*=>>advanced.Structural#s1().*/
2525
val s1x/*<<=advanced.Test.s1x.*/ = /*=>>scala.reflect.Selectable.reflectiveSelectable().*/s/*=>>advanced.Test.s.*/.s1/*=>>advanced.Structural#s1().*//*=>>scala.Selectable#selectDynamic().*/.x
2626
val s2/*<<=advanced.Test.s2.*/ = s/*=>>advanced.Test.s.*/.s2/*=>>advanced.Structural#s2().*/

tests/semanticdb/Annotations.expect.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.annotation.meta._
55
import scala.language/*=>>scalaShadowing.language.*/.experimental/*=>>scalaShadowing.language.experimental.*/.macros/*=>>scalaShadowing.language.experimental.macros.*/
66

77
@ClassAnnotation/*=>>com.javacp.annot.ClassAnnotation#*/
8-
class /*=>>java.lang.Object#`<init>`().*/Annotations/*<<=annot.Annotations#*/[@Type/*<<=annot.Annotations#`<init>`().*/ParameterAnnotation/*=>>com.javacp.annot.TypeParameterAnnotation#*/ T/*<<=annot.Annotations#`<init>`().[T]*//*<<=annot.Annotations#[T]*/](@ParameterAnnotation/*=>>com.javacp.annot.ParameterAnnotation#*/ x/*<<=annot.Annotations#`<init>`().(x)*//*<<=annot.Annotations#(x)*/: T/*=>>annot.Annotations#`<init>`().[T]*/) { self/*<<=local0*/: AnyRef/*=>>scala.AnyRef#*/ =>
8+
class Annotations/*<<=annot.Annotations#*/[@TypeParameterAnnotation/*=>>com.javacp.annot.TypeParameterAnnotation#*/ T/*<<=annot.Annotations#[T]*/](@ParameterAnnotation/*=>>com.javacp.annot.ParameterAnnotation#*/ x/*<<=annot.Annotations#x.*/: T/*=>>annot.Annotations#`<init>`().[T]*/) { self/*<<=local0*/: AnyRef/*=>>scala.AnyRef#*/ =>
99
@FieldAnnotation/*=>>com.javacp.annot.FieldAnnotation#*/
1010
val field/*<<=annot.Annotations#field.*/ = 42
1111

@@ -19,20 +19,20 @@ class /*=>>java.lang.Object#`<init>`().*/Annotations/*<<=annot.Annotations#*/[@T
1919
type S/*<<=annot.Annotations#S#*/
2020
}
2121

22-
class /*=>>java.lang.Object#`<init>`().*/B/*<<=annot.B#*/ @Cons/*<<=annot.B#`<init>`().*/tructorAnnotation/*=>>com.javacp.annot.ConstructorAnnotation#*/()(x/*<<=annot.B#`<init>`().(x)*//*<<=annot.B#(x)*/: Int/*=>>scala.Int#*/) {
22+
class B/*<<=annot.B#*/ @ConstructorAnnotation/*=>>com.javacp.annot.ConstructorAnnotation#*/()(x/*<<=annot.B#x.*/: Int/*=>>scala.Int#*/) {
2323
@ConstructorAnnotation/*=>>com.javacp.annot.ConstructorAnnotation#*/
2424
def this()/*<<=annot.B#`<init>`(+1).*/ = this(/*=>>annot.B#`<init>`().*/42)
2525
}
2626

2727
@ObjectAnnotation/*=>>com.javacp.annot.ObjectAnnotation#*/
28-
object /*=>>java.lang.Object#`<init>`().*/M/*<<=annot.M.*/ {
29-
/*=>>scala.package.Serializable#*//*=>>scala.*//*=>>_root_*//*=>>annot.M.*/@MacroAnnotation/*=>>com.javacp.annot.MacroAnnotation#*/
28+
object M/*<<=annot.M.*/ {
29+
@MacroAnnotation/*=>>com.javacp.annot.MacroAnnotation#*/
3030
def m/*<<=annot.M.m().*/[TT/*<<=annot.M.m().[TT]*/]: Int/*=>>scala.Int#*//*=>>scala.Predef.`???`().*//*=>>scala.Predef.*//*=>>scala.*//*=>>_root_*/ = macro ???
3131
}
3232

3333
@TraitAnnotation/*=>>com.javacp.annot.TraitAnnotation#*/
3434
trait T/*<<=annot.T#*/
3535

36-
object /*=>>java.lang.Object#`<init>`().*/Alias/*<<=annot.Alias.*/ {
37-
/*=>>scala.package.Serializable#*//*=>>scala.*//*=>>_root_*//*=>>annot.Alias.*/type A/*<<=annot.Alias.A#*/ = ClassAnnotation/*=>>com.javacp.annot.ClassAnnotation#*/ @param
36+
object Alias/*<<=annot.Alias.*/ {
37+
type A/*<<=annot.Alias.A#*/ = ClassAnnotation/*=>>com.javacp.annot.ClassAnnotation#*/ @param
3838
}

tests/semanticdb/Anonymous.expect.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package example
22
import scala.language/*=>>scalaShadowing.language.*/.higherKinds/*=>>scalaShadowing.language.higherKinds.*/
33

4-
class /*=>>java.lang.Object#`<init>`().*/Anonymous/*<<=example.Anonymous#*/ {
4+
class Anonymous/*<<=example.Anonymous#*/ {
55
this: Anonymous/*=>>example.Anonymous#*/ =>
66

77
def locally/*<<=example.Anonymous#locally().*/[A/*<<=example.Anonymous#locally().[A]*/](x/*<<=example.Anonymous#locally().(x)*/: A/*=>>example.Anonymous#locally().[A]*/): A/*=>>example.Anonymous#locally().[A]*/ = x/*=>>example.Anonymous#locally().(x)*/
@@ -16,5 +16,5 @@ class /*=>>java.lang.Object#`<init>`().*/Anonymous/*<<=example.Anonymous#*/ {
1616
}
1717

1818
trait Foo/*<<=example.Anonymous#Foo#*/
19-
/*=>>java.lang.Object#`<init>`().*/new Foo/*=>>example.Anonymous#Foo#*/ {}
19+
new Foo/*=>>example.Anonymous#Foo#*/ {}
2020
}

tests/semanticdb/Classes.expect.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package classes
2+
3+
class C1/*<<=classes.C1#*/(val x1/*<<=classes.C1#x1.*/: Int/*=>>scala.Int#*/) extends AnyVal/*=>>scala.AnyVal#*//*=>>scala.AnyVal#`<init>`().*/
4+
5+
class C2/*<<=classes.C2#*/(val x2/*<<=classes.C2#x2.*/: Int/*=>>scala.Int#*/) extends AnyVal/*=>>scala.AnyVal#*//*=>>scala.AnyVal#`<init>`().*/
6+
object C2/*<<=classes.C2.*/
7+
8+
case class C3/*<<=classes.C3#*/(x/*<<=classes.C3#x.*/: Int/*=>>scala.Int#*/)
9+
10+
case class C4/*<<=classes.C4#*/(x/*<<=classes.C4#x.*/: Int/*=>>scala.Int#*/)
11+
object C4/*<<=classes.C4.*/
12+
13+
object M/*<<=classes.M.*/ {
14+
implicit class C5/*<<=classes.M.C5#*/(x/*<<=classes.M.C5#x.*/: Int/*=>>scala.Int#*/)
15+
}
16+
17+
case class C6/*<<=classes.C6#*/(private val x/*<<=classes.C6#x.*/: Int/*=>>scala.Int#*/)
18+
19+
class C7/*<<=classes.C7#*/(x/*<<=classes.C7#x.*/: Int/*=>>scala.Int#*/)
20+
21+
class C8/*<<=classes.C8#*/(private[this] val x/*<<=classes.C8#x.*/: Int/*=>>scala.Int#*/)
22+
23+
class C9/*<<=classes.C9#*/(private[this] var x/*<<=classes.C9#x().*/: Int/*=>>scala.Int#*/)
24+
25+
object N/*<<=classes.N.*/ {
26+
val anonClass/*<<=classes.N.anonClass.*/ = new C7/*=>>classes.C7#*//*=>>classes.C7#`<init>`().*/(42) {
27+
val local/*<<=local0*/ = ???/*=>>scala.Predef.`???`().*/
28+
}
29+
val anonFun/*<<=classes.N.anonFun.*/ = List/*=>>scala.package.List().*//*=>>scala.collection.IterableFactory#apply().*/(1).map/*=>>scala.collection.immutable.List#map().*/ { i =>
30+
val local = 2
31+
local/*=>>local1*/ +/*=>>scala.Int#`+`(+4).*/ 2
32+
}
33+
}

tests/semanticdb/Classes.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package classes
2+
3+
class C1(val x1: Int) extends AnyVal
4+
5+
class C2(val x2: Int) extends AnyVal
6+
object C2
7+
8+
case class C3(x: Int)
9+
10+
case class C4(x: Int)
11+
object C4
12+
13+
object M {
14+
implicit class C5(x: Int)
15+
}
16+
17+
case class C6(private val x: Int)
18+
19+
class C7(x: Int)
20+
21+
class C8(private[this] val x: Int)
22+
23+
class C9(private[this] var x: Int)
24+
25+
object N {
26+
val anonClass = new C7(42) {
27+
val local = ???
28+
}
29+
val anonFun = List(1).map { i =>
30+
val local = 2
31+
local + 2
32+
}
33+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package a
2-
object /*=>>java.lang.Object#`<init>`().*/Definitions/*<<=a.Definitions.*/ {
3-
/*=>>scala.package.Serializable#*//*=>>scala.*//*=>>_root_*//*=>>a.Definitions.*/val a/*<<=a.Definitions.a.*/ = 1
2+
object Definitions/*<<=a.Definitions.*/ {
3+
val a/*<<=a.Definitions.a.*/ = 1
44
var b/*<<=a.Definitions.b.*/ =/*<<=a.Definitions.`b_=`().*/ 2
55
def c/*<<=a.Definitions.c().*/ = 3
6-
class /*=>>java.lang.Object#`<init>`().*/D/*<<=a.Definitions.D#*/
6+
class D/*<<=a.Definitions.D#*/
77
trait E/*<<=a.Definitions.E#*/
88
}

0 commit comments

Comments
 (0)