metals icon indicating copy to clipboard operation
metals copied to clipboard

Asterisk to underscore replacement when organizing imports in Scala 3

Open DLakomy opened this issue 9 months ago • 2 comments

Steps to reproduce:

  1. Create a project by sbt new scala/scala3.g8
  2. 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!")
  1. Add empty .scalafix.conf file next to build.sbt (it doesn't have to be empty, but its presence seems to be necessary to reproduce the problem).
  2. Run Organize Imports action, for instance by pressing Cmd+Shift+P, type Organize Imports, press Return (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

DLakomy avatar Apr 28 '24 21:04 DLakomy

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.

tgodzik avatar Apr 29 '24 07:04 tgodzik

OrganizeImports.targetDialect = Scala3 works correctly, thank you.

I confirm, with no .scalafix.conf this doesn't happen.

DLakomy avatar Apr 29 '24 08:04 DLakomy