Open ckipp01 opened 2 years ago
Thanks for reporting this @caenrique! You're correct, this shouldn't happen. I'd expect the user to see a nicer message this this, not an Internal error
message. We need to handle this a bit differently in Metals, so I've moved this issue over to the main repo since that's where the fix will be.
Thanks for reporting! So the question here is whether we should just show a nicer error or maybe we should add OrganizeImports by default ?
So the question here is whether we should just show a nicer error or maybe we should add OrganizeImports by default ?
I came up with three options (1 is the easiest, 3 is the richest, I guess)
run_scalafix
if rules are unavailable.
rules are missing, please create .scalafix.conf and configure rules with
rules = [ ... ]` (?).scalafmt.conf
, but I'm not sure what kind of rules should be on in the created file.Yea I'm sort of liking iii
since it would most closely align with the behavior of triggering scalafmt for the first time. The only tricky this is that if we do this, then users will expect it to work with organize imports and it will with Metals maybe, but not with their build tool or others on their team using IntelliJ for example. Full circle makes me wish dependencies could be defined in your .scalafix.conf
file.
Another easy alternative to i
is just show a nice warning to the user that they have no .scalafix.conf
file and that they should just set it up if they'd like to use the command.
If you decide to go for i
, it would/will benefit from https://github.com/scalacenter/scalafix/pull/1624
Full circle makes me wish dependencies could be defined in your .scalafix.conf file.
That's definitely something that would be beneficial to all scalafix clients, and it wouldn't be too hard to implement by inferring a high-level tool-classpath from dependencies optionally listed in the conf file. I understand it would reduce the complexity of the ScalafixProvider
here, but how would it help in that particular issue?
I understand it would reduce the complexity of the ScalafixProvider here, but how would it help in that particular issue?
Sure, to expand on the example I had, let's pretend that we create a .scalafix.conf
file for the user, but it's empty. However when the user triggers run scalafix
and we organize imports for example the user will still get their imports organized. Then they check in their code with this new .scalafix.conf
with their build tool still needing to add that external rule. Whereas if you could include an external dep in your .scalafix.conf
file then when metals creates it with the necessary stuff, the user wouldn't need to remember to change their build definition at all, just add sbt-scalafix or use scalafix cli in CI etc. Does that make sense?
Thanks @ckipp01, very clear - I added https://github.com/scalacenter/scalafix/issues/1625 to track the feature request.
Discussed in https://github.com/scalameta/nvim-metals/discussions/420