Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor validateWorkspace to handle missing custom scalafmtConfigPath gracefully and log warning #7080

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scala.concurrent.Future
import scala.concurrent.Promise
import scala.util.Failure
import scala.util.Success
import scala.util.Try

import scala.meta._
import scala.meta.internal.io.FileIO
Expand Down Expand Up @@ -405,13 +406,17 @@ final class FormattingProvider(
def validateWorkspace(projectRoot: AbsolutePath): Future[Unit] = {
scalafmtConf(projectRoot) match {
case Some(conf) =>
val text = conf.toInputFromBuffers(buffers).text
ScalafmtConfig.parse(text) match {
case Failure(e) =>
scribe.error(s"Failed to parse ${conf}", e)
getTextFromBuffers(conf) match {
case Some(text) =>
ScalafmtConfig.parse(text) match {
case Failure(e) =>
scribe.error(s"Failed to parse ${conf}", e)
Future.unit
case Success(values) =>
checkIfDialectUpgradeRequired(values, conf)
}
case None =>
Future.unit
case Success(values) =>
checkIfDialectUpgradeRequired(values, conf)
}
case None =>
Future.unit
Expand All @@ -430,6 +435,16 @@ final class FormattingProvider(
configpath.orElse(default)
}

private def getTextFromBuffers(conf: AbsolutePath): Option[String] = {
Try(conf.toInputFromBuffers(buffers).text) match {
case Success(text) =>
Some(text)
case Failure(exception) =>
scribe.warn(s"Unable to get content from $conf", exception)
None
}
}

private def activeReporter(projectRoot: AbsolutePath): ScalafmtReporter =
new ScalafmtReporter {
private var downloadingScalafmt = Promise[Unit]()
Expand Down
Loading