Skip to content

Commit 08efb4f

Browse files
authored
Merge pull request #237 from scala/backport-lts-3.3-22484
Backport "improvement: use heuristic to figure out `nameSpan` if `pointDelta` too big" to 3.3 LTS
2 parents e6067f8 + 07bea7e commit 08efb4f

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,11 @@ object Trees {
460460
else if qualifier.span.exists && qualifier.span.start > span.point then // right associative
461461
val realName = name.stripModuleClassSuffix.lastPart
462462
Span(span.start, span.start + realName.length, point)
463-
else
464-
Span(point, span.end, point)
463+
else if span.pointMayBeIncorrect then
464+
val realName = name.stripModuleClassSuffix.lastPart
465+
val probablyPoint = span.end - realName.length
466+
Span(probablyPoint, span.end, probablyPoint)
467+
else Span(point, span.end, point)
465468
else span
466469
}
467470

compiler/src/dotty/tools/dotc/util/Spans.scala

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ object Spans {
5959
if (poff == SyntheticPointDelta) start else start + poff
6060
}
6161

62+
def pointMayBeIncorrect =
63+
pointDelta == 0 && end - start >= SyntheticPointDelta
64+
6265
/** The difference between point and start in this span */
6366
def pointDelta: Int =
6467
(coords >>> (StartEndBits * 2)).toInt

presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala

+24
Original file line numberDiff line numberDiff line change
@@ -1462,5 +1462,29 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite:
14621462
|""".stripMargin
14631463
)
14641464

1465+
@Test def i3053 =
1466+
check(
1467+
s"""import Aaaa.*
1468+
|
1469+
|def classDef2(cdef: List[Int]): Int = {
1470+
| def aaa(ddef: Thicket2): List[Int] = ddef match {
1471+
| case Thicket2(_) => ???
1472+
| }
1473+
|${("//" + "x" * 64 + "\n") * 64}
1474+
| 1
1475+
|}.<<showing2>>("aaa")
1476+
|
1477+
|case class Thicket2(trees: List[Int]) {}
1478+
|
1479+
|object Aaaa {
1480+
| extension [T](x: T)
1481+
| def <<show@@ing2>>[U](aaa: String): T = {
1482+
| x
1483+
| }
1484+
|}
1485+
|
1486+
|""".stripMargin
1487+
)
1488+
14651489

14661490
end DocumentHighlightSuite

0 commit comments

Comments
 (0)