Skip to content

Commit

Permalink
chore: Add more information about classpath and compiler options when…
Browse files Browse the repository at this point in the history
… severe error happens
  • Loading branch information
tgodzik committed Jan 2, 2024
1 parent 240a406 commit e3d8eac
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ abstract class CompilerAccess[Reporter, Compiler](
config: PresentationCompilerConfig,
sh: Option[ScheduledExecutorService],
newCompiler: () => CompilerWrapper[Reporter, Compiler],
shouldResetJobQueue: Boolean
shouldResetJobQueue: Boolean,
additionalReportingData: () => String
)(implicit ec: ExecutionContextExecutor, rc: ReportContext) {

def this(
config: PresentationCompilerConfig,
sh: Option[ScheduledExecutorService],
newCompiler: () => CompilerWrapper[Reporter, Compiler],
shouldResetJobQueue: Boolean
)(implicit ec: ExecutionContextExecutor, rc: ReportContext) =
this(config, sh, newCompiler, shouldResetJobQueue, () => "")

private val logger: Logger =
Logger.getLogger(classOf[CompilerAccess[_, _]].getName)

Expand Down Expand Up @@ -198,6 +208,9 @@ abstract class CompilerAccess[Reporter, Compiler](
Report(
"compiler-error",
s"""|occurred in the presentation compiler.
|
|presentation compiler configuration:
|${additionalReportingData()}
|
|action parameters:
|${params.map(_.printed()).getOrElse("<NONE>")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ class ScalaCompilerWrapper(global: MetalsGlobal)
class ScalaCompilerAccess(
config: PresentationCompilerConfig,
sh: Option[ScheduledExecutorService],
newCompiler: () => ScalaCompilerWrapper
newCompiler: () => ScalaCompilerWrapper,
additionalReportingData: () => String
)(implicit ec: ExecutionContextExecutor, rc: ReportContext)
extends CompilerAccess[StoreReporter, MetalsGlobal](
config,
sh,
newCompiler,
shouldResetJobQueue = false
shouldResetJobQueue = false,
additionalReportingData
) {

def newReporter = new StoreReporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ case class ScalaPresentationCompiler(
new ScalaCompilerAccess(
config,
sh,
() => new ScalaCompilerWrapper(newCompiler())
() => new ScalaCompilerWrapper(newCompiler()),
{ () =>
s"""|Scala version: $scalaVersion
|Classpath:
|${classpath
.map(path => s"$path [${if (path.exists) "exists" else "missing"} ]")
.mkString(", ")}
|Options:
|${options.mkString(" ")}
|""".stripMargin
}
)(
ec,
reportContex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Scala3CompilerAccess(
config: PresentationCompilerConfig,
sh: Option[ScheduledExecutorService],
newCompiler: () => Scala3CompilerWrapper,
additionalReportingData: () => String,
)(using ec: ExecutionContextExecutor, rc: ReportContext)
extends CompilerAccess[StoreReporter, MetalsDriver](
config,
Expand All @@ -22,6 +23,7 @@ class Scala3CompilerAccess(
* Otherwise it will block indefinetely in case of infinite loops.
*/
shouldResetJobQueue = true,
additionalReportingData,
):

def newReporter = new StoreReporter(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scala.meta.internal.metals.ReportContext
import scala.meta.internal.metals.ReportLevel
import scala.meta.internal.metals.StdReportContext
import scala.meta.internal.mtags.BuildInfo
import scala.meta.internal.mtags.MtagsEnrichments.given
import scala.meta.internal.pc.completions.CompletionProvider
import scala.meta.internal.pc.completions.OverrideCompletions
import scala.meta.pc.*
Expand Down Expand Up @@ -64,6 +65,15 @@ case class ScalaPresentationCompiler(
config,
sh,
() => new Scala3CompilerWrapper(newDriver),
() =>
s"""|Scala version: $scalaVersion
|Classpath:
|${classpath
.map(path => s"$path [${if path.exists then "exists" else "missing"} ]")
.mkString(", ")}
|Options:
|${options.mkString(" ")}
|""".stripMargin,
)(using
ec
)
Expand Down

0 comments on commit e3d8eac

Please sign in to comment.