Skip to content

Commit 9ef5579

Browse files
committed
improvement: use heuristic to figure out nameSpan if pointDelta to big
1 parent 0e567c1 commit 9ef5579

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

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

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

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

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

1465+
@Test def i3053 =
1466+
check(
1467+
"""import Aaaa.*
1468+
|
1469+
|def classDef2(cdef: List[Int]): Int = {
1470+
| def aaa(ddef: Thicket2): List[Int] = ddef match {
1471+
| case Thicket2(_) => ???
1472+
| }
1473+
|
1474+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1475+
| * inline classes
1476+
| */
1477+
| // The original type and value parameters in the constructor already have the flags
1478+
| // needed to be type members (i.e. param, and possibly also private and local unless
1479+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1480+
| // go in `constr`, the constructor after desugaring.
1481+
|
1482+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1483+
| * inline classes
1484+
| */
1485+
| // The original type and value parameters in the constructor already have the flags
1486+
| // needed to be type members (i.e. param, and possibly also private and local unless
1487+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1488+
| // go in `constr`, the constructor after desugaring.
1489+
|
1490+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1491+
| * inline classes
1492+
| */
1493+
| // Annotations on class _type_ parameters are set on the derived parameters
1494+
| // but not on the constructor parameters. The reverse is true for
1495+
| // annotations on class _value_ parameters.
1496+
| // The original type and value parameters in the constructor already have the flags
1497+
| // needed to be type members (i.e. param, and possibly also private and local unless
1498+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1499+
| // go in `constr`, the constructor after desugaring.
1500+
| // The original type and value parameters in the constructor already have the flags
1501+
| // needed to be type members (i.e. param, and possibly also private and local unless
1502+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1503+
| // go in `constr`, the constructor after desugaring.
1504+
|
1505+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1506+
| * inline classes
1507+
| */
1508+
| // The original type and value parameters in the constructor already have the flags
1509+
| // needed to be type members (i.e. param, and possibly also private and local unless
1510+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1511+
| // go in `constr`, the constructor after desugaring.
1512+
|
1513+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1514+
| * inline classes
1515+
| */
1516+
|
1517+
| // Annotations on class _type_ parameters are set on the derived parameters
1518+
| // but not on the constructor parameters. The reverse is true for
1519+
| // annotations on class _value_ parameters.
1520+
| // The original type and value parameters in the constructor already have the flags
1521+
| // needed to be type members (i.e. param, and possibly also private and local unless
1522+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1523+
| // go in `constr`, the constructor after desugaring.
1524+
| // The original type and value parameters in the constructor already have the flags
1525+
| // needed to be type members (i.e. param, and possibly also private and local unless
1526+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1527+
| // go in `constr`, the constructor after desugaring.
1528+
|
1529+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1530+
| * inline classes
1531+
| */
1532+
| // The original type and value parameters in the constructor already have the flags
1533+
| // needed to be type members (i.e. param, and possibly also private and local unless
1534+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1535+
| // go in `constr`, the constructor after desugaring.
1536+
|
1537+
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
1538+
| * inline classes
1539+
| */
1540+
| // Annotations on class _type_ parameters are set on the derived parameters
1541+
| // but not on the constructor parameters. The reverse is true for
1542+
| // annotations on class _value_ parameters.
1543+
| // The original type and value parameters in the constructor already have the flags
1544+
| // needed to be type members (i.e. param, and possibly also private and local unless
1545+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1546+
| // go in `constr`, the constructor after desugaring.
1547+
| // The original type and value parameters in the constructor already have the flags
1548+
| // needed to be type members (i.e. param, and possibly also private and local unless
1549+
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
1550+
| // go in `constr`, the constructor after desugaring.
1551+
| 1
1552+
|}.<<showing2>>("aaa")
1553+
|
1554+
|case class Thicket2(trees: List[Int]) {}
1555+
|
1556+
|object Aaaa {
1557+
| extension [T](x: T)
1558+
| def <<show@@ing2>>[U](aaa: String): T = {
1559+
| x
1560+
| }
1561+
|}
1562+
|
1563+
|""".stripMargin
1564+
)
1565+
14651566

14661567
end DocumentHighlightSuite

0 commit comments

Comments
 (0)