Skip to content

Commit

Permalink
Close global after compute ondemand semanticdb files
Browse files Browse the repository at this point in the history
  • Loading branch information
mlachkar committed Mar 4, 2021
1 parent 32a03fb commit 3e8fb47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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
17 changes: 15 additions & 2 deletions 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 @@ -267,7 +269,6 @@ object MainOps {
)
} catch {
case NonFatal(_) =>
args.global.restart()
TextDocument.defaultInstance
}
g.unitOfFile.clear()
Expand Down Expand Up @@ -326,7 +327,7 @@ object MainOps {
args.parse(input).get: Tree
}
val doc = SyntacticDocument(input, tree, args.diffDisable, args.config)
if (args.rules.isSemantic) {
val results = if (args.rules.isSemantic) {
val relpath = file.toRelative(args.sourceroot)
val sdoc = SemanticDocument.fromPath(
doc,
Expand All @@ -347,6 +348,18 @@ object MainOps {
} else {
args.rules.syntacticPatch(doc, args.args.autoSuppressLinterErrors)
}
// close global if evaluated
cleanGlobalRessources(args.global)
results
}

private def cleanGlobalRessources(global: LazyValue[Option[Global]]): Unit = {
if (global.isEvaluated)
global.value.foreach { g =>
g.askShutdown()
g.closeCompat()
}
else ()
}

def previewPatches(
Expand Down

0 comments on commit 3e8fb47

Please sign in to comment.