Skip to content

Commit

Permalink
Make doc work with sbt 1.4.x
Browse files Browse the repository at this point in the history
Scaladoc are not generated with 1.4.0-M2:
sbt/sbt#5798. There seemed to be three problems:
1. the sources were not actually specified in ScaladocBridge
2. Three was an assumption that the compiler would return only
   AbstractZincFiles in DelegatingReporter.makePosition but, in doc at
   least, it returns scala.reflect.io.PlainFile

These are straightforward to fix though I am somewhat concerned that the
pattern match in DelegatingReporter has an unhandled case.
  • Loading branch information
eatkins committed Aug 31, 2020
1 parent 7ed4374 commit 53bc41a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.Optional
import scala.reflect.internal.util.{ FakePos, NoPosition, Position }
// Left for compatibility
import Compat._
import scala.reflect.io.PlainFile

private object DelegatingReporter {
def apply(settings: scala.tools.nsc.Settings, delegate: xsbti.Reporter): DelegatingReporter =
Expand Down Expand Up @@ -89,7 +90,10 @@ private object DelegatingReporter {

def makePosition(pos: Position): xsbti.Position = {
val src = pos.source
val sourcePath = src.file match { case AbstractZincFile(virtualFile) => virtualFile.id }
val sourcePath = src.file match {
case AbstractZincFile(virtualFile) => virtualFile.id
case f: PlainFile => f.file.toString
}
val sourceFile = new File(src.file.path)
val line = pos.line
val lineContent = pos.lineContent.stripLineEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ private class Runner(
import scala.tools.nsc.{ doc, Global, reporters }
import reporters.Reporter
val docSettings: doc.Settings = new doc.Settings(Log.settingsError(log))
val command = new CompilerCommand(args.toList, docSettings)
val fullArgs = args.toList ++ sources.map(_.toString)
val command = new CompilerCommand(fullArgs, docSettings)
val reporter = DelegatingReporter(docSettings, delegate)
def noErrors = !reporter.hasErrors && command.ok

def run(): Unit = {
debug(log, "Calling Scaladoc with arguments:\n\t" + args.mkString("\n\t"))
debug(log, "Calling Scaladoc with arguments:\n\t" + fullArgs.mkString("\n\t"))
if (noErrors) {
import doc._ // 2.8 trunk and Beta1-RC4 have doc.DocFactory. For other Scala versions, the next line creates forScope.DocFactory
val processor = new DocFactory(reporter, docSettings)
Expand Down

0 comments on commit 53bc41a

Please sign in to comment.