Skip to content

[2.x] fix: Resolve virtual file refs in scaladoc options#8768

Merged
eed3si9n merged 1 commit intosbt:developfrom
speedcoder430:fix/scaladoc-semanticdb-8740
Feb 20, 2026
Merged

[2.x] fix: Resolve virtual file refs in scaladoc options#8768
eed3si9n merged 1 commit intosbt:developfrom
speedcoder430:fix/scaladoc-semanticdb-8740

Conversation

@speedcoder430
Copy link
Copy Markdown
Contributor

Problem

Fixes #8740

When semanticdbEnabled := true is set on Scala 2.x projects, the doc task fails because ${CSR_CACHE} placeholders in scalacOptions (specifically the -Xplugin: path for the semanticdb compiler plugin JAR) are not resolved before being passed to Scaladoc. This causes:

[error] bad option: -P:semanticdb:targetroot:/path/to/target/meta
[error] (Compile / doc) Scaladoc generation failed

The root cause is that the plugin JAR path contains an unresolved ${CSR_CACHE} variable, so the plugin fails to load, and its associated -P:semanticdb:* flags are rejected as unknown options.

Reproduction (from #8740)

// build.sbt
semanticdbEnabled := true
scalaVersion := "2.12.21"
sbt> doc
[error] bad option: -P:semanticdb:targetroot:...

Solution

Resolve virtual file references (containing $) in scalacOptions before passing them to the Scaladoc bridge in docTaskSettings. This matches the approach already used in zinc's MixedAnalyzingCompiler.compileScala() (see sbt/zinc#1545), which resolves $ variables for compilation but not for doc generation.

The resolution splits each option by : and ,, then converts any part containing $ via VirtualFileRef.of() -> converter.toPath().

Tests

  • New project/semanticdb-doc scripted test: runs doc on a Scala 2.12 project with semanticdbEnabled := true
  • Ran project/*, actions/*, compiler-project/* scripted test suites locally — all pass

AI Disclosure

This PR was developed with assistance from GitHub Copilot (Claude Opus 4.6). All code changes, test design, and debugging were AI-assisted.

Generated-by: GitHub Copilot (Claude Opus 4.6)

When `semanticdbEnabled := true` is set on Scala 2.x projects, the
`doc` task fails because `${CSR_CACHE}` placeholders in scalacOptions
(specifically the `-Xplugin:` path for the semanticdb compiler plugin)
are not resolved before being passed to Scaladoc.

This fix resolves virtual file references (containing $) in
scalacOptions before passing them to the Scaladoc bridge, matching
what zinc's MixedAnalyzingCompiler already does for compilation
(see sbt/zinc#1545).

Fixes sbt#8740

Generated-by: GitHub Copilot (Claude Opus 4.6)
Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. lgtm pending CI.

@speedcoder430
Copy link
Copy Markdown
Contributor Author

speedcoder430 commented Feb 20, 2026

Thanks for the contribution. lgtm pending CI.

Thanks for approving my PR. Seems CI passed successfully.

Comment on lines +2067 to +2073
def convertVfRef(value: String): String =
if !value.contains("$") then value
else converter.toPath(VirtualFileRef.of(value)).toString
val resolvedOptions = options.map { x =>
if !x.contains("$") then x
else x.split(":").map(_.split(",").map(convertVfRef).mkString(",")).mkString(":")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally, this should be pushed to Zinc, but I'm fine with this workaround for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks

@eed3si9n eed3si9n merged commit a00814a into sbt:develop Feb 20, 2026
15 checks passed
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.x] scaladoc failure when semanticdbEnabled is enabled on scala 2.x projects

2 participants