From 9ef55796d7f72085657b014bbef25aa1bb77478d Mon Sep 17 00:00:00 2001 From: kasiaMarek Date: Thu, 30 Jan 2025 14:05:27 +0100 Subject: [PATCH 1/2] improvement: use heuristic to figure out `nameSpan` if `pointDelta` to big --- compiler/src/dotty/tools/dotc/ast/Trees.scala | 7 +- .../src/dotty/tools/dotc/util/Spans.scala | 3 + .../highlight/DocumentHighlightSuite.scala | 101 ++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 4c7ca396117e..fdefc14aadd6 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -461,8 +461,11 @@ object Trees { else if qualifier.span.exists && qualifier.span.start > span.point then // right associative val realName = name.stripModuleClassSuffix.lastPart Span(span.start, span.start + realName.length, point) - else - Span(point, span.end, point) + else if span.pointMayBeIncorrect then + val realName = name.stripModuleClassSuffix.lastPart + val probablyPoint = span.end - realName.length + Span(probablyPoint, span.end, probablyPoint) + else Span(point, span.end, point) else span } diff --git a/compiler/src/dotty/tools/dotc/util/Spans.scala b/compiler/src/dotty/tools/dotc/util/Spans.scala index e1487408f36b..7d4bbe0e8180 100644 --- a/compiler/src/dotty/tools/dotc/util/Spans.scala +++ b/compiler/src/dotty/tools/dotc/util/Spans.scala @@ -59,6 +59,9 @@ object Spans { if (poff == SyntheticPointDelta) start else start + poff } + def pointMayBeIncorrect = + pointDelta == 0 && end - start >= SyntheticPointDelta + /** The difference between point and start in this span */ def pointDelta: Int = (coords >>> (StartEndBits * 2)).toInt diff --git a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala index 5d9893f6a1c1..0586a0648ac3 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala @@ -1462,5 +1462,106 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite: |""".stripMargin ) + @Test def i3053 = + check( + """import Aaaa.* + | + |def classDef2(cdef: List[Int]): Int = { + | def aaa(ddef: Thicket2): List[Int] = ddef match { + | case Thicket2(_) => ??? + | } + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | // Annotations on class _type_ parameters are set on the derived parameters + | // but not on the constructor parameters. The reverse is true for + | // annotations on class _value_ parameters. + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | + | // Annotations on class _type_ parameters are set on the derived parameters + | // but not on the constructor parameters. The reverse is true for + | // annotations on class _value_ parameters. + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | + | /** Does `tree' look like a reference to AnyVal? Temporary test before we have + | * inline classes + | */ + | // Annotations on class _type_ parameters are set on the derived parameters + | // but not on the constructor parameters. The reverse is true for + | // annotations on class _value_ parameters. + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | // The original type and value parameters in the constructor already have the flags + | // needed to be type members (i.e. param, and possibly also private and local unless + | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that + | // go in `constr`, the constructor after desugaring. + | 1 + |}.<>("aaa") + | + |case class Thicket2(trees: List[Int]) {} + | + |object Aaaa { + | extension [T](x: T) + | def <>[U](aaa: String): T = { + | x + | } + |} + | + |""".stripMargin + ) + end DocumentHighlightSuite From a6252544116df0a6f80f8937d9f52532760b8001 Mon Sep 17 00:00:00 2001 From: kasiaMarek Date: Thu, 6 Feb 2025 15:20:08 +0100 Subject: [PATCH 2/2] test: shorten test --- .../highlight/DocumentHighlightSuite.scala | 81 +------------------ 1 file changed, 2 insertions(+), 79 deletions(-) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala index 0586a0648ac3..4809bc5cd5b8 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala @@ -1464,90 +1464,13 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite: @Test def i3053 = check( - """import Aaaa.* + s"""import Aaaa.* | |def classDef2(cdef: List[Int]): Int = { | def aaa(ddef: Thicket2): List[Int] = ddef match { | case Thicket2(_) => ??? | } - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | // Annotations on class _type_ parameters are set on the derived parameters - | // but not on the constructor parameters. The reverse is true for - | // annotations on class _value_ parameters. - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | - | // Annotations on class _type_ parameters are set on the derived parameters - | // but not on the constructor parameters. The reverse is true for - | // annotations on class _value_ parameters. - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | - | /** Does `tree' look like a reference to AnyVal? Temporary test before we have - | * inline classes - | */ - | // Annotations on class _type_ parameters are set on the derived parameters - | // but not on the constructor parameters. The reverse is true for - | // annotations on class _value_ parameters. - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. - | // The original type and value parameters in the constructor already have the flags - | // needed to be type members (i.e. param, and possibly also private and local unless - | // prefixed by type or val). `tparams` and `vparamss` are the type parameters that - | // go in `constr`, the constructor after desugaring. + |${("//" + "x" * 64 + "\n") * 64} | 1 |}.<>("aaa") |