Skip to content

Commit

Permalink
bugfix: Correctly check if a given config exists in scalafix.conf
Browse files Browse the repository at this point in the history
Fixes #6886
  • Loading branch information
tgodzik committed Oct 31, 2024
1 parent e3812b3 commit b37c906
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,10 @@ case class ScalafixProvider(
None
}
(for {
config <- scalaconfFileText
text <- scalaconfFileText
config = ConfigFactory.parseString(text)
newSettings = amendSettings.filterNot { case (name, _) =>
config.contains(name)
config.hasPath(name)
}
if !newSettings.isEmpty
} yield {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,58 @@ class ScalafixProviderLspSuite extends BaseLspSuite("scalafix-provider") {
)
} yield ()
}
test("no-amend-scalafix-conf") {
cleanWorkspace()

client.showMessageRequestHandler = params =>
if (
params
.getMessage()
.contains(
"Your `.scalafix.conf` misses the following settings for organize imports"
)
)
fail("No amend message should be shown")
else {
None
}

for {
_ <- initialize(
s"""|/metals.json
|{"a":{"scalaVersion": "${V.scala3}" }}
|/a/src/main/scala/Main.scala
|import java.util.concurrent.*
|import java.util.*
|/.scalafix.conf
|rules = [
| OrganizeImports
|]
|OrganizeImports = {
| targetDialect = Scala3
|}
|""".stripMargin
)
_ <- server.didOpen("a/src/main/scala/Main.scala")
textParams =
new TextDocumentPositionParams(
new TextDocumentIdentifier(
workspace.resolve("a/src/main/scala/Main.scala").toURI.toString()
),
new Position(0, 0),
)
_ <- server.executeCommand(
ServerCommands.RunScalafix,
textParams,
)
contents = server.bufferContents("a/src/main/scala/Main.scala")
_ = assertNoDiff(
contents,
"""|import java.util.*
|import java.util.concurrent.*
|""".stripMargin,
)
} yield ()
}

}

0 comments on commit b37c906

Please sign in to comment.