feat: pass scalac options to presentation compiler#1271
Open
warcholjakub wants to merge 4 commits intoscalacenter:mainfrom
Open
feat: pass scalac options to presentation compiler#1271warcholjakub wants to merge 4 commits intoscalacenter:mainfrom
warcholjakub wants to merge 4 commits intoscalacenter:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
scalacOptionsend-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
ScastieMetalsOptionsadded a new field but still uses CircederiveDecoder. Circe’s generic derivation doesn’t populate missing fields from Scala default args, so older clients that omitscalacOptionswill fail decoding. To keep backward compatibility, consider makingscalacOptionsanOption[List[String]](mappingNonetoNil), or provide a custom decoder that treats a missingscalacOptionsfield asNil.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes false diagnostics when using capture checking or other compiler flags set via
//> using optionorscalacOptions.