Skip to content

Surface Scalafix errors better #6049

Open
@ckipp01

Description

@ckipp01

Describe the bug

I think there are situations where we can do a better job of surfacing the ScalafixRunException that we have. For example I was just working on a project and I copied over a .scalafix.conf file from another project:

rules = [
  OrganizeImports,
  ExplicitResultTypes,
  RemoveUnused
]

RemoveUnused.imports = false

OrganizeImports.groupedImports = Explode
OrganizeImports.expandRelative = true
OrganizeImports.removeUnused = true

When triggering it in Metals all I see is:

[nvim-metals] Could not execute command: Internal error.

The reason for this is that the command fails, but the issue is only found in the Metals logs and there is no indication a user should look there. This specific instance the error reported by Scalafix is actually really useful and shows exactly what is wrong:

SEVERE: Internal error: scala.meta.internal.metals.ScalafixProvider$ScalafixRunException: "OrganizeImports.removeUnused" is not supported on Scala 3 as the compiler is not providing enough information. Run the rule with "OrganizeImports.removeUnused" set to false to organize imports while keeping potentially unused imports.
java.util.concurrent.CompletionException: scala.meta.internal.metals.ScalafixProvider$ScalafixRunException: "OrganizeImports.removeUnused" is not supported on Scala 3 as the compiler is not providing enough information. Run the rule with "OrganizeImports.removeUnused" set to false to organize imports while keeping potentially unused imports.
        at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:331)
        at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:346)
        at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:704)
        at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
        at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
        at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:29)
        at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:26)
        at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:484)
        at scala.concurrent.ExecutionContext$parasitic$.execute(ExecutionContext.scala:222)
        at scala.concurrent.impl.Promise$Transformation.submitWithValue(Promise.scala:429)
        at scala.concurrent.impl.Promise$DefaultPromise.submitWithValue(Promise.scala:338)
        at scala.concurrent.impl.Promise$DefaultPromise.tryComplete0(Promise.scala:285)
        at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:504)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: scala.meta.internal.metals.ScalafixProvider$ScalafixRunException: "OrganizeImports.removeUnused" is not supported on Scala 3 as the compiler is not providing enough information. Run the rule with "OrganizeImports.removeUnused" set to false to organize imports while keeping potentially unused imports.
        at scala.meta.internal.metals.ScalafixProvider.$anonfun$runScalafixRules$1(ScalafixProvider.scala:163)
        at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
        ... 3 more

Expected behavior

Since this is actionable I'd expect this message to be surfaced to the user so they can easily see what is wrong in their config and fix it.

Operating system

macOS

Editor/Extension

Nvim (nvim-metals)

Version of Metals

1.2.0+87-6b8b0081-SNAPSHOT

Extra context or search terms

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementNot a bug or a feature, but something general we can improvescalafixRelating to the built-in scalafix support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions