Skip to content

Commit a00814a

Browse files
[2.x] fix: Resolve virtual file refs in scaladoc options (sbt#8768)
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)
1 parent c045c72 commit a00814a

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

main/src/main/scala/sbt/Defaults.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,13 @@ object Defaults extends BuildCommon {
20642064
if (ScalaArtifacts.isScala3(sv)) Opts.doc.externalAPIScala3(xapisFiles)
20652065
else Opts.doc.externalAPI(xapisFiles)
20662066
val options = sOpts ++ externalApiOpts
2067+
def convertVfRef(value: String): String =
2068+
if !value.contains("$") then value
2069+
else converter.toPath(VirtualFileRef.of(value)).toString
2070+
val resolvedOptions = options.map { x =>
2071+
if !x.contains("$") then x
2072+
else x.split(":").map(_.split(",").map(convertVfRef).mkString(",")).mkString(":")
2073+
}
20672074
val scalac = cs.scalac match
20682075
case ac: AnalyzingCompiler => ac.onArgs(Compiler.exported(s, "scaladoc"))
20692076
val docSrcFiles = if ScalaArtifacts.isScala3(sv) then tFiles else srcs
@@ -2077,7 +2084,7 @@ object Defaults extends BuildCommon {
20772084
cp.map(converter.toPath).map(new sbt.internal.inc.PlainVirtualFile(_)),
20782085
converter,
20792086
out.toPath(),
2080-
options,
2087+
resolvedOptions,
20812088
maxErrors.value,
20822089
s.log,
20832090
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semanticdbEnabled := true
2+
scalaVersion := "2.12.21"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
object A
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# scaladoc should succeed when semanticdbEnabled is true
2+
> doc

0 commit comments

Comments
 (0)