Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Config: make withDialect a public method #4849

Merged
merged 3 commits into from
Feb 28, 2025
Merged

Conversation

kitbellew
Copy link
Collaborator

@kitbellew kitbellew commented Feb 26, 2025

Also:

  • remove local copies of dialects: they are completely identical to the originals and they also convey the impression that their type is NamedDialect when it is just Dialect
  • replace NamedDialect with sourcecode.Text[Dialect]: this will allow passing a properly named variable containing just a dialect to a method expecting a "named dialect"

@SethTisue
Copy link
Contributor

when compiling Scastie against this PR, I still see:

[error] /Users/tisue/cb3/newdir/sbt-runner/src/main/scala/com.olegych.scastie.sbt/FormatActor.scala:29:21: type mismatch;
[error]  found   : scala.meta.Dialect
[error]  required: org.scalafmt.config.NamedDialect
[error]       }.withDialect(dialect)
[error]                     ^
[error] one error found

so it seems the status quo has not been restored

I was able to get it to compile with

-      }.withDialect(dialect)
+      }.withDialect(NamedDialect(NamedDialect.getName(dialect).get, dialect))

but this seems infelicitous and may actually be incorrect at runtime for all I know; it's just blind fumbling with code I don't understand the context of

They are completely identical to the originals and they also convey the
impression that their type is NamedDialect when it is just Dialect.
@kitbellew
Copy link
Collaborator Author

when compiling Scastie against this PR, I still see:

[error] /Users/tisue/cb3/newdir/sbt-runner/src/main/scala/com.olegych.scastie.sbt/FormatActor.scala:29:21: type mismatch;
[error]  found   : scala.meta.Dialect
[error]  required: org.scalafmt.config.NamedDialect
[error]       }.withDialect(dialect)
[error]                     ^
[error] one error found

so it seems the status quo has not been restored

I was able to get it to compile with

-      }.withDialect(dialect)
+      }.withDialect(NamedDialect(NamedDialect.getName(dialect).get, dialect))

but this seems infelicitous and may actually be incorrect at runtime for all I know; it's just blind fumbling with code I don't understand the context of

generally, the expectation was one wouldn't call runnerSettings.withDialect directly...

instead of

      val dialect =
        if (scalaTarget.scalaVersion.startsWith("2.12")) NamedDialect.scala212
        else if (scalaTarget.scalaVersion.startsWith("2.13")) NamedDialect.scala213
        else if (scalaTarget.scalaVersion.startsWith("3")) NamedDialect.scala3
        else NamedDialect.scala213

      val runner = {
        if (isWorksheetMode && scalaTarget.hasWorksheetMode)
          RunnerSettings.sbt
        else
          RunnerSettings.default
      }.withDialect(dialect)

      ScalafmtConfig.default.copy(runner = runner)

with the new interface one would use

      import scala.meta.dialects

      val dialect: NamedDialect =
        if (scalaTarget.scalaVersion.startsWith("2.12.")) dialects.Scala212
        else if (scalaTarget.scalaVersion.startsWith("3.")) dialects.Scala3
        else dialects.Scala213

      ScalafmtConfig.default.withDialect(dialect)

Also, RunnerSettings.sbt is the same as RunnerSettings.default.

@kitbellew kitbellew merged commit 89e5985 into scalameta:main Feb 28, 2025
22 checks passed
@kitbellew kitbellew deleted the 4849 branch February 28, 2025 15:43
@SethTisue
Copy link
Contributor

thanks @kitbellew , that's super helpful

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants