Skip to content

Commit

Permalink
improvement: use heuristic to figure out nameSpan if pointDelta t…
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik authored Feb 7, 2025
2 parents d60a914 + a625254 commit bb2aadb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/util/Spans.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,5 +1462,29 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite:
|""".stripMargin
)

@Test def i3053 =
check(
s"""import Aaaa.*
|
|def classDef2(cdef: List[Int]): Int = {
| def aaa(ddef: Thicket2): List[Int] = ddef match {
| case Thicket2(_) => ???
| }
|${("//" + "x" * 64 + "\n") * 64}
| 1
|}.<<showing2>>("aaa")
|
|case class Thicket2(trees: List[Int]) {}
|
|object Aaaa {
| extension [T](x: T)
| def <<show@@ing2>>[U](aaa: String): T = {
| x
| }
|}
|
|""".stripMargin
)


end DocumentHighlightSuite

0 comments on commit bb2aadb

Please sign in to comment.