Skip to content

Selection range omits closing paren #22566

Open
@harpocrates

Description

Compiler version

3.6.3

Minimized code

Requesting selection ranges with cursor at @@ below:

object Main extends App {
  def x = 12 * (34 + 5@@6)
}

Output

The selection ranges returned are:

  • 56 (good)
  • 34 + 56 (good)
  • 12 * (34 + 56 (not good)

Expectation

The final selection range should be 12 * (34 + 56) (with the closing paren).


Here's a patch to produce a test case for this.

diff --git a/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala
index e277a67c46..a600d3e4d7 100644
--- a/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala
+++ b/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala
@@ -147,3 +147,21 @@ class SelectionRangeSuite extends BaseSelectionRangeSuite:
            |}""".stripMargin
       )
     )
+
+  @Test def `arithmetic` =
+    check(
+      """|object Main extends App {
+         |  def x = 12 * (34 + 5@@6)
+         |}""".stripMargin,
+      List[String](
+        """|object Main extends App {
+           |  def x = 12 * (34 + >>region>>56<<region<<)
+           |}""".stripMargin,
+        """|object Main extends App {
+           |  def x = 12 * (>>region>>34 + 56<<region<<)
+           |}""".stripMargin,
+        """|object Main extends App {
+           |  def x = >>region>>12 * (34 + 56)<<region<<
+           |}""".stripMargin
+      )
+    )

Here's the output of running that test at time of reporting

sbt:scala3> scala3-presentation-compiler/testOnly dotty.tools.pc.tests.SelectionRangeSuite -- dotty.tools.pc.tests.SelectionRangeSuite.arithmetic
[info] Test run dotty.tools.pc.tests.SelectionRangeSuite started
[info] Test dotty.tools.pc.tests.SelectionRangeSuite.arithmetic started
[error] Test dotty.tools.pc.tests.SelectionRangeSuite.arithmetic failed: java.lang.AssertionError: 
[error]  (+++ Expected, --- Obtained, NO CHANGES)
[error] 
[error]   object Main extends App {
[error] +   def x = >>region>>12 * (34 + 56)<<region<<
[error] -   def x = >>region>>12 * (34 + 56<<region<<)
[error]   }
[error] 
[error] , took 0.286 sec
[info] Test run dotty.tools.pc.tests.SelectionRangeSuite finished: 1 failed, 0 ignored, 1 total, 0.289s
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]         dotty.tools.pc.tests.SelectionRangeSuite
[error] (scala3-presentation-compiler / Test / testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 4 s, completed Feb 9, 2025, 3:48:22 PM

Metadata

Assignees

No one assigned

    Labels

    SpreeSuitable for a future Spreearea:presentation-compilerRelated to the presentation compiler module used by Metals and possibly other toolsitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions