Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Issue with scala3 * imports and IntelliJ #197

Open
guizmaii opened this issue Aug 3, 2021 · 8 comments
Open

Issue with scala3 * imports and IntelliJ #197

guizmaii opened this issue Aug 3, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@guizmaii
Copy link

guizmaii commented Aug 3, 2021

Hi,

IntelliJ organises the imports this way:

import zio.test.*
import zio.test.Assertion.*

while OrganizeImports organises them this way:

import zio.test.Assertion.*
import zio.test.*

Here's my scalafix config concerning OrganizeImports:

OrganizeImports {
  # Allign with IntelliJ IDEA so that they don't fight each other
  groupedImports = Merge
}

I feel that IntelliJ is right on this one.
What do you thing?

@liancheng
Copy link
Owner

This behavior is controlled by the importsOrder option. Setting it to SymbolsFirst should produce the desired result.

BTW, Scala 3 support is still experimental and only available in master. Are you using some master snapshot version?

@guizmaii
Copy link
Author

guizmaii commented Aug 4, 2021

It solves the problem but creates another one:

IntelliJ organises these imports like this:

import io.circe.syntax.*
import io.circe.{Encoder, Json}

while with importsOrder set to SymbolsFirst, OrganizeImports organize them this way:

import io.circe.{Encoder, Json}
import io.circe.syntax.*

Are you using some master snapshot version?

No, I'm using the latest published one.

@liancheng
Copy link
Owner

liancheng commented Aug 4, 2021

Huh, interesting. Could you please share your IntelliJ configuration relevant to import organization? Specifically:

  1. Editor / Code Style / Scala / Formatter: Are you using "IntelliJ" or "Scalafmt"
  2. If you are using the "IntelliJ" importer, in the "Imports" tab, which option are you using for "Sort imports (for optimize imports)"? Is it "lexicographically" or "scalastyle consistent"?

I suspect you are using the Scalastyle flavor? IIRC, Scalastyle uses a complicated sorting rule that I never quite understand...

@guizmaii
Copy link
Author

guizmaii commented Aug 5, 2021

Editor / Code Style / Scala / Formatter: Are you using "IntelliJ" or "Scalafmt"

Screenshot 2021-08-05 at 10 12 47

@liancheng
Copy link
Owner

@guizmaii, could you please also share your .scalafmt.conf?

@guizmaii
Copy link
Author

guizmaii commented Aug 6, 2021

Here it is:

version = "2.7.5"
maxColumn = 140
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses.preset = true
optIn.annotationNewlines = true
newlines.alwaysBeforeMultilineDef = false
trailingCommas = preserve

rewrite.rules = [RedundantBraces]

rewrite.redundantBraces.generalExpressions = false
rewriteTokens = {
  "⇒": "=>"
  "→": "->"
  "←": "<-"
}

@liancheng liancheng added the bug Something isn't working label Aug 17, 2021
@liancheng
Copy link
Owner

liancheng commented Aug 17, 2021

@guizmaii, what I can confirm is that OrganizeImports does not handle the Scala 3 * wildcard properly when sorting imports. What OrganizeImports does when SymbolsFirst is used is to replace underscores and braces with \u0001 and \u0002 followed by a normal lexicographical sorting. The * wildcard is not handled yet.

But I haven't figured out how exactly the result you hit was produced. Need some more time for this.

@mihaisoloi
Copy link

To add to this, removeUnused doesn't work for imports that are specified using the * wildcard.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants