metals icon indicating copy to clipboard operation
metals copied to clipboard

Range selection selects whole line instead of all parameters in method

Open HoSzyk opened this issue 1 year ago • 2 comments

When doing range selection on a whole line gets selected def foo(a: Int, b: Int) = ???

Expected behaviour:

a: Int, b: Int gets selected

Operating system: Mac OS X

Java version: 17.0.8

Editor/extension: Visual Studio Code v1.84.2

Metals version: 1.1.0

Extra context or search terms:

Workspace information:

  • Scala versions: 3.3.1
  • Build tools: sbt
  • Build servers: sbt v1.8.2
  • All build tools in workspace: Bloop; sbt

HoSzyk avatar Nov 30 '23 16:11 HoSzyk

Thanks for reporting! This should actually be pretty simple to fix.

The implementation is in:

  • https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-2/scala/meta/internal/pc/SelectionRangeProvider.scala for Scala 2
  • https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-3/scala/meta/internal/pc/SelectionRangeProvider.scala for Scala 3

Tests are located in https://github.com/scalameta/metals/blob/main/tests/cross/src/test/scala/tests/pc/SelectionRangeSuite.scala

We can match on DefDef while going through tree path and in that case add an additional SelectionRange for all the parameters.

tgodzik avatar Dec 01 '23 13:12 tgodzik

I don't know why this closed automatically but it seems like some kind of bug in GitHub. I'll reopen this as it is still unfixed for mtags 2 and 3.

rochala avatar Feb 29 '24 09:02 rochala