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

Close global after compute ondemand semanticdb files #1348

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
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 @@ -383,7 +383,7 @@ case class Args(
settings.YpresentationAnyThread.value = true
settings.classpath.value = validatedClasspath.syntax
val reporter = new StoreReporter()
new Global(settings, reporter)
new Global(settings, reporter, "Scalafix")
})
}

Expand Down
16 changes: 15 additions & 1 deletion scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import java.nio.file.attribute.BasicFileAttributes

import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer
import scala.tools.nsc.interactive.Global
import scala.util.Failure
import scala.util.Success
import scala.util.Try
Expand All @@ -37,6 +38,7 @@ import org.typelevel.paiges.{Doc => D}
import scalafix.Versions
import scalafix.cli.ExitStatus
import scalafix.interfaces.ScalafixEvaluation
import scalafix.internal.compat.CompilerCompat.XtensionGlobal
import scalafix.internal.config.PrintStreamReporter
import scalafix.internal.diff.DiffUtils
import scalafix.internal.interfaces.ScalafixEvaluationImpl
Expand Down Expand Up @@ -132,6 +134,7 @@ object MainOps {
}
// Then afterComplete for each rule
args.rules.rules.foreach(_.afterComplete())
shutdownCompiler(args.global)

ScalafixEvaluationImpl.from(fileEvaluations, ExitStatus.Ok)
} else
Expand Down Expand Up @@ -267,7 +270,6 @@ object MainOps {
)
} catch {
case NonFatal(_) =>
args.global.restart()
bjaglin marked this conversation as resolved.
Show resolved Hide resolved
TextDocument.defaultInstance
}
g.unitOfFile.clear()
Expand Down Expand Up @@ -349,6 +351,17 @@ object MainOps {
}
}

private def shutdownCompiler(global: LazyValue[Option[Global]]): Unit = {
global.foreach(_.foreach(g => {
try {
g.askShutdown()
g.closeCompat()
} catch {
case NonFatal(_) =>
}
}))
}

def previewPatches(
patches: Seq[v0.Patch],
ctx: RuleCtx,
Expand Down Expand Up @@ -440,6 +453,7 @@ object MainOps {
}

args.rules.rules.foreach(_.afterComplete())
shutdownCompiler(args.global)

adjustExitCode(args, exit, files)
}
Expand Down