scalameta / metals-feature-requests

Issue tracker for Metals feature requests
37 stars 4 forks source link

Allow specifying scalafmt config choices #363

Open keynmol opened 8 months ago

keynmol commented 8 months ago

Is your feature request related to a problem? Please describe.

Currently Metals suggests creating Scalafmt config on first issue of the formatting request.

By default, it adds a very unopinionated config (e.g. here for Scala 3 project):

version = "3.7.14"
runner.dialect = scala3

While convenient, this is quite limited.

For example, in pretty much all of my project I use the same Scalafmt config starter:

runner.dialect = scala3
rewrite.scala3.insertEndMarkerMinLines = 10
rewrite.scala3.removeOptionalBraces = true
rewrite.scala3.convertToNewSyntax = true

Other people might have different options. On a normal week I create dozens of throwaway Scala scripts and worksheet sessions, where I'd want to have consistent formatting (well, consistent according to my tastes, of course, everyone is different).

FR: I would like the ability to customise the scalafmt config that Metals creates

Describe the solution you'd like

I propose having a configuration setting that Metals accepts, which creates a named list of Scalafmt config options:

{
  "metals": {
    "scalafmtTemplates": {
      "scala3": {
         "options": "runner.dialect = scala3\nrewrite.scala3.insertEndMarkerMinLines = 10\nrewrite.scala3.removeOptionalBraces = true",
         "defaultForScala3": true
      },
      "scala2-cross-bla": {...}
    }
  }
}

Describe alternatives you've considered

Manual management of Scalafmt configs, but this is quite cumbersome. I believe silently creating scalafmt config if the user explicitly configured their Metals is a good UX.

Additional context

No response

Search terms

scalafmt, metals, config