metals
metals copied to clipboard
Asterisk to underscore replacement when organizing imports in Scala 3
Steps to reproduce:
- Create a project by
sbt new scala/scala3.g8
- Change the
main.scala
contents to this (the important thing is to add some unsorted imports):
import java.util.concurrent.*
import java.util.*
@main def hello(): Unit =
println("Hello world!")
- Add empty
.scalafix.conf
file next tobuild.sbt
(it doesn't have to be empty, but its presence seems to be necessary to reproduce the problem). - Run
Organize Imports
action, for instance by pressing Cmd+Shift+P, typeOrganize Imports
, pressReturn
(Enter
)
The result is :
import java.util._
import java.util.concurrent._
...
Expected behaviour:
The result should be:
import java.util.*
import java.util.concurrent.*
...
Operating system: Mac OS X
Java version: 17.0.8
Editor/extension: Visual Studio Code v1.88.1
Metals version: 1.3.0
Extra context or search terms:
I think it didn't happen in Metals 1.2.0 (with scalafix.conf
containing only one line, OrganizeImports.removeUnused = false
, to silence an error). The issue is quite similar to #5121, but it's marked as solved and is quite old, so I thought I should submit this one.
Workspace information:
- Scala versions: 3.4.1; 2.12.18
- Build tools: 0. sbt
- Build servers: 0. Bloop v1.5.17
- All build tools in workspace: Bloop; sbt
Thanks for reporting! You should be able to use:
OrganizeImports.targetDialect = Scala3
With no .scalafix.conf this doesn't happen?
We should make sure this doesn't happen by default.
OrganizeImports.targetDialect = Scala3
works correctly, thank you.
I confirm, with no .scalafix.conf
this doesn't happen.