Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop on erroneous doc command #10738

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -67,3 +67,6 @@ jitwatch.out
project/**/metals.sbt

.bsp

# the essential editor
**/*.swp
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/Driver.scala
Expand Up @@ -28,7 +28,7 @@ abstract class Driver {

/** Forward errors to the (current) reporter. */
protected def scalacError(msg: String): Unit = {
reporter.error(FakePos("scalac"), msg + "\n scalac -help gives more information")
reporter.error(FakePos("scalac"), s"$msg\n scalac -help gives more information")
}

/** True to continue compilation. */
Expand Down
28 changes: 16 additions & 12 deletions src/scaladoc/scala/tools/nsc/ScalaDoc.scala
Expand Up @@ -21,35 +21,38 @@ import scala.reflect.internal.util.{FakePos, Position}
* that generates documentation from source files.
*/
class ScalaDoc {
import ScalaDoc._
val versionMsg = s"Scaladoc ${Properties.versionString} -- ${Properties.copyrightString}"

def process(args: Array[String]): Boolean = {
var reporter: ScalaDocReporter = null
val docSettings = new doc.Settings(msg => reporter.error(FakePos("scaladoc"), msg + "\n scaladoc -help gives more information"),
val docSettings = new doc.Settings(msg => reporter.error(NoDocPos, s"$msg\n scaladoc -help gives more information"),
msg => reporter.echo(msg),
DefaultPathFactory)
reporter = new ScalaDocReporter(docSettings)
val command = new ScalaDoc.Command(args.toList, docSettings)
val command = new Command(args.toList, docSettings)
def hasFiles = command.files.nonEmpty || docSettings.uncompilableFiles.nonEmpty

if (docSettings.version.value)
if (!command.ok)
()
else if (docSettings.version.value)
reporter.echo(versionMsg)
else if (docSettings.Xhelp.value)
reporter.echo(command.xusageMsg)
else if (docSettings.Yhelp.value)
reporter.echo(command.yusageMsg)
else if (docSettings.showPlugins.value)
reporter.warning(null, "Plugins are not available when using Scaladoc")
reporter.warning(NoDocPos, "Plugins are not available when using Scaladoc")
else if (docSettings.showPhases.value)
reporter.warning(null, "Phases are restricted when using Scaladoc")
reporter.warning(NoDocPos, "Phases are restricted when using Scaladoc")
else if (docSettings.help.value || !hasFiles)
reporter.echo(command.usageMsg)
else
try { new DocFactory(reporter, docSettings) document command.files }
try new DocFactory(reporter, docSettings).document(command.files)
catch {
case ex @ FatalError(msg) =>
if (docSettings.isDebug) ex.printStackTrace()
reporter.error(null, "fatal error: " + msg)
reporter.error(NoDocPos, s"fatal error: $msg")
}
finally reporter.finish()

Expand Down Expand Up @@ -86,13 +89,14 @@ class ScalaDocReporter(settings: Settings) extends ConsoleReporter(settings) {
}

object ScalaDoc extends ScalaDoc {
val NoDocPos = FakePos("scaladoc")

class Command(arguments: List[String], settings: doc.Settings) extends CompilerCommand(arguments, settings) {
override def cmdName = "scaladoc"
override def usageMsg = (
createUsageMsg("where possible scaladoc", explain = false)(x => x.isStandard && settings.isScaladocSpecific(x.name)) +
"\n\nStandard scalac options also available:" +
optionsMessage(x => x.isStandard && !settings.isScaladocSpecific(x.name))
)
override def usageMsg =
sm"""${createUsageMsg("where possible scaladoc", explain = false)(x => x.isStandard && settings.isScaladocSpecific(x.name))}
|Standard scalac options also available:
|${optionsMessage(x => x.isStandard && !settings.isScaladocSpecific(x.name))}"""
}

def main(args: Array[String]): Unit = {
Expand Down