Describe the bug
Code action "Organize Imports" does not organize imports nor does it reports any errors in the UI, Doctor or metals.log
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Organize imports should work for Scala 2.11.12 or provide clear information why it is not working.
Installation:
Additional context
Hi guys! I am huge fan of the work you are doing here.
I have been trying out the new organize imports feature. I work on a lot of projects that use Spark 2.x as a dependency, which means that they still use Scala 2.11.12.
I also managed to do some debugging. Metals tries to download artifact com.github.liancheng::organize-imports_2.11:0.4.0, but the organize-imports scalafix rule is not published for 2.11.
A possible solution is to use scalafix and scalafix rules compiled for 2.12 regardless of project version. I am actually using the organize-imports rule (compiled for 2.12) in a 2.11.12 project with the gradle-scalafix plugin and it works fine.
The downside is that this approach would hinder usage of some scalafix rules that need the scala version in the build to match scala version of scalafix (ExplicitResultTypes for example). For me personally, that is trade-off I would be willing to accept for organize imports to work.
Regardless of the solution, user should be informed when a Code Action fails . The current implementation does not propagate failure information to LSP client - failure to fetch artifacts results success with no edits.
Search terms
organize imports, scalafix
Thank you for for trying the feature and reporting this issue!
At a quick glance, it seems that the easiest solution would be to cross-publish organize-imports for 2.11 as well. I took a stab at it, here's the PR https://github.com/liancheng/scalafix-organize-imports/pull/113. The major notable thing is that 2.11 won't allow accurate removal of unused imports (due to buggy or missing warnings), but it's probably something we can live with.
You also make a good point about error reporting, but I'll leave it to @tgodzik / @mlachkar to decide what's the best strategy for that.
The major notable thing is that 2.11 won't allow accurate removal of unused imports (due to buggy or missing warnings), but it's probably something we can live with.
Actually, nevermind, I was wrong. It's fine when using the right flag (-Ywarn-unused-import for 2.11). See https://github.com/liancheng/scalafix-organize-imports/pull/114
Awesome! Thanks @gabro ! I think that was the best way to go.
https://github.com/scalameta/metals/pull/2101 fixed the issue with Scala 2.11.12 馃憤
Should I open another issue regarding the error reporting?
2101 fixed the issue with Scala 2.11.12
Should I open another issue regarding the error reporting?
Might be actually good to do. The issue here is solved and I think it makes sense to follow up with another.
Most helpful comment
Actually, nevermind, I was wrong. It's fine when using the right flag (
-Ywarn-unused-importfor 2.11). See https://github.com/liancheng/scalafix-organize-imports/pull/114