Skip to content

feat: pass scalac options to presentation compiler#1271

Open
warcholjakub wants to merge 4 commits intoscalacenter:mainfrom
warcholjakub:fix/cc-live-diagnostics
Open

feat: pass scalac options to presentation compiler#1271
warcholjakub wants to merge 4 commits intoscalacenter:mainfrom
warcholjakub:fix/cc-live-diagnostics

Conversation

@warcholjakub
Copy link
Copy Markdown
Collaborator

Fixes false diagnostics when using capture checking or other compiler flags set via //> using option or scalacOptions.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR propagates user-specified scalacOptions (from Scala CLI directives and sbt scalacOptions) into the Metals presentation compiler configuration to reduce incorrect/false diagnostics.

Changes:

  • Add extraction/filtering of “PC-relevant” scalac flags from Scala CLI directives and sbt config.
  • Extend Metals configuration models/plumbing to carry scalacOptions end-to-end (client → metals-runner → presentation compiler).
  • Add unit tests for option extraction/filtering for both Scala CLI and sbt inputs.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scala-cli-runner/src/test/scala/org/scastie/scalacli/ScalaCliScalacOptionsTest.scala Adds tests for extracting PC-relevant options from Scala CLI directives.
sbt-runner/src/test/scala/org/scastie/sbt/SbtScalacOptionsTest.scala Adds tests for extracting/filtering PC-relevant options from sbt scalacOptions.
metals-runner/src/main/scala/org/scastie/metals/PresentationCompilers.scala Passes extracted scalacOptions into newInstance when creating presentation compilers.
metals-runner/src/main/scala/org/scastie/metals/MetalsDispatcher.scala Threads configuration.scalacOptions into presentation compiler creation.
client/src/main/scala/org/scastie/client/scalacli/ScalaCliUtils.scala Extends parse result to include extracted Scala CLI PC scalac options.
client/src/main/scala/org/scastie/client/components/editor/MetalsClient.scala Includes scalacOptions in ScastieMetalsOptions sent to Metals backend.
client/src/main/scala/org/scastie/client/components/editor/InteractiveProvider.scala Stores/passes scalac options; triggers Metals reconfigure when options change.
client/src/main/scala/org/scastie/client/components/editor/CodeEditor.scala Adds pcScalacOptions prop for Metals configuration.
client/src/main/scala/org/scastie/client/components/MainPanel.scala Wires pcScalacOptions into CodeEditor (currently only for sbt inputs).
api/src/main/scala/org/scastie/api/Inputs.scala Adds PC-relevant filtering and option extraction helpers for sbt + Scala CLI inputs.
api/src/main/scala/org/scastie/api/ApiModels.scala Extends ScastieMetalsOptions API model with scalacOptions.
Comments suppressed due to low confidence (1)

api/src/main/scala/org/scastie/api/ApiModels.scala:78

  • ScastieMetalsOptions added a new field but still uses Circe deriveDecoder. Circe’s generic derivation doesn’t populate missing fields from Scala default args, so older clients that omit scalacOptions will fail decoding. To keep backward compatibility, consider making scalacOptions an Option[List[String]] (mapping None to Nil), or provide a custom decoder that treats a missing scalacOptions field as Nil.
case class ScastieMetalsOptions(dependencies: Set[ScalaDependency], scalaTarget: ScalaTarget, scalacOptions: List[String] = Nil)

object ScastieMetalsOptions {
  implicit val scastieMetalsOptionsEncoder: Encoder[ScastieMetalsOptions] = deriveEncoder[ScastieMetalsOptions]
  implicit val scastieMetalsOptionsDecoder: Decoder[ScastieMetalsOptions] = deriveDecoder[ScastieMetalsOptions]
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread api/src/main/scala/org/scastie/api/Inputs.scala Outdated
Comment thread api/src/main/scala/org/scastie/api/Inputs.scala Outdated
Comment thread client/src/main/scala/org/scastie/client/components/MainPanel.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants