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

chore: Add more information about classpath and compiler options when severe error happens #5986

Merged
merged 1 commit into from
Jan 2, 2024
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 @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference between this and giving a default value to the additionalReportingData arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is for the JVM, it fails in with the default argument.

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
Loading