Skip to content

Selection range omits closing paren #22566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
harpocrates opened this issue Feb 9, 2025 · 0 comments · Fixed by #22702
Closed

Selection range omits closing paren #22566

harpocrates opened this issue Feb 9, 2025 · 0 comments · Fixed by #22702
Assignees
Labels
area:presentation-compiler Related to the presentation compiler module used by Metals and possibly other tools itype:bug Spree Suitable for a future Spree

Comments

@harpocrates
Copy link
Contributor

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
@harpocrates harpocrates added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 9, 2025
@Gedochao Gedochao added area:presentation-compiler Related to the presentation compiler module used by Metals and possibly other tools Spree Suitable for a future Spree and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 11, 2025
@tgodzik tgodzik closed this as completed in 107a2f1 May 6, 2025
tgodzik pushed a commit to scala/scala3-lts that referenced this issue May 12, 2025
…22702)

Thanks to @NPCRUS @Yummy-Yums for taking a part in a spree. Sorry for
taking that long to create a PR, but I was unavailable.

Fixes scala#22566

---------

Co-authored-by: NPCRUS <[email protected]>
Co-authored-by: Yummy-Yums <[email protected]>
tgodzik added a commit to scala/scala3-lts that referenced this issue May 12, 2025
…22702)

Thanks to @NPCRUS @Yummy-Yums for taking a part in a spree. Sorry for
taking that long to create a PR, but I was unavailable.

Fixes scala#22566

---------

Co-authored-by: NPCRUS <[email protected]>
Co-authored-by: Yummy-Yums <[email protected]>
[Cherry-picked 107a2f1][modified]
odersky pushed a commit to dotty-staging/dotty that referenced this issue May 12, 2025
…22702)

Thanks to @NPCRUS @Yummy-Yums for taking a part in a spree. Sorry for
taking that long to create a PR, but I was unavailable.

Fixes scala#22566

---------

Co-authored-by: NPCRUS <[email protected]>
Co-authored-by: Yummy-Yums <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:presentation-compiler Related to the presentation compiler module used by Metals and possibly other tools itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants