From 8c34b401e608f8c0ffd846497d44748911444eda Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 25 Jun 2021 14:38:17 +0200 Subject: [PATCH 1/2] Add no links warning setting to scaladoc --- .../src/tests/noLinkWarnings.scala | 14 ++++++++++++++ .../src/dotty/tools/scaladoc/Scaladoc.scala | 2 ++ .../tools/scaladoc/ScaladocSettings.scala | 6 ++++++ .../scaladoc/tasty/comments/Comments.scala | 10 ++++------ .../tasty/comments/MemberLookup.scala | 6 +++--- .../no-link-warnings/LinkWarningTest.scala | 19 +++++++++++++++++++ .../no-link-warnings/NoLinkWarningsTest.scala | 18 ++++++++++++++++++ 7 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 scaladoc-testcases/src/tests/noLinkWarnings.scala create mode 100644 scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala create mode 100644 scaladoc/test/dotty/tools/scaladoc/no-link-warnings/NoLinkWarningsTest.scala diff --git a/scaladoc-testcases/src/tests/noLinkWarnings.scala b/scaladoc-testcases/src/tests/noLinkWarnings.scala new file mode 100644 index 000000000000..f888a843e432 --- /dev/null +++ b/scaladoc-testcases/src/tests/noLinkWarnings.scala @@ -0,0 +1,14 @@ +package tests +package noLinkWarnings + +/** + * [[doesnt.exist]] + * + */ +class NoLinkWarnings + + +/** + * [[NoLinkWarnings]] + */ +class Exists diff --git a/scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala b/scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala index 8b3dd57697c2..1c2610ca62d7 100644 --- a/scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala +++ b/scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala @@ -52,6 +52,7 @@ object Scaladoc: documentSyntheticTypes: Boolean = false, snippetCompiler: List[String] = Nil, snippetCompilerDebug: Boolean = false, + noLinkWarnings: Boolean = false, versionsDictionaryUrl: Option[String] = None ) @@ -196,6 +197,7 @@ object Scaladoc: docCanonicalBaseUrl.get, YdocumentSyntheticTypes.get, snippetCompiler.get, + noLinkWarnings.get, snippetCompilerDebug.get, versionsDictionaryUrl.nonDefault ) diff --git a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala index c857f37222fc..bd7c2a45e503 100644 --- a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala +++ b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala @@ -93,6 +93,12 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings: "./docs" ) + val noLinkWarnings: Setting[Boolean] = BooleanSetting( + "-no-link-warnings", + "Avoid warnings for ambiguous and incorrect links ONLY in members look up. Doesn't affect incorrect links of assets etc.", + false + ) + val versionsDictionaryUrl: Setting[String] = StringSetting( "-versions-dictionary-url", "versions dictionary url", diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala index 066b7b5173c4..345b2399abe8 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/Comments.scala @@ -109,12 +109,10 @@ abstract class MarkupConversion[T](val repr: Repr)(using dctx: DocContext) { case None => val txt = s"No DRI found for query" val msg = s"$txt: $queryStr" - // TODO change to the commented-out version when we'll get rid of the warnings in stdlib - // report.warning( - // msg, - // owner.pos.get.asInstanceOf[dotty.tools.dotc.util.SrcPos], - // ) - report.inform(msg) + + if (!summon[DocContext].args.noLinkWarnings) then + report.warning(msg, owner.pos.get.asInstanceOf[dotty.tools.dotc.util.SrcPos]) + DocLink.UnresolvedDRI(queryStr, txt) private val SchemeUri = """[a-z]+:.*""".r diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala index a6da58ab3e71..ee5ae7f1bd71 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala @@ -86,9 +86,9 @@ trait MemberLookup { res catch case e: Exception => - // TODO (https://github.com/lampepfl/scala3doc/issues/238): proper reporting - val msg = s"Unable to find a link for ${query} ${ownerOpt.fold("")(o => "in " + o.name)}" - report.warn(msg, e) + if (!summon[DocContext].args.noLinkWarnings) then + val msg = s"Unable to find a link for ${query} ${ownerOpt.fold("")(o => "in " + o.name)}" + report.warn(msg, e) None private def hackMembersOf(using Quotes)(rsym: reflect.Symbol) = { diff --git a/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala new file mode 100644 index 000000000000..3861e63dcdda --- /dev/null +++ b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala @@ -0,0 +1,19 @@ +package dotty.tools.scaladoc +package noLinkWarnings + +import org.junit.Assert.assertEquals + +class LinkWarningsTest extends ScaladocTest("noLinkWarnings"): + + override def args = Scaladoc.Args( + name = "test", + tastyFiles = tastyFiles(name), + output = getTempDir().getRoot, + projectVersion = Some("1.0") + ) + + override def runTest = afterRendering { + val diagnostics = summon[DocContext].compilerContext.reportedDiagnostics + assertEquals("There should be exaclyt one warning", 1, diagnostics.warningMsgs.size) + assertNoErrors(diagnostics) + } diff --git a/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/NoLinkWarningsTest.scala b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/NoLinkWarningsTest.scala new file mode 100644 index 000000000000..c24842411781 --- /dev/null +++ b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/NoLinkWarningsTest.scala @@ -0,0 +1,18 @@ +package dotty.tools.scaladoc +package noLinkWarnings + +class NoLinkWarningsTest extends ScaladocTest("noLinkWarnings"): + + override def args = Scaladoc.Args( + name = "test", + tastyFiles = tastyFiles(name), + output = getTempDir().getRoot, + projectVersion = Some("1.0"), + noLinkWarnings = true + ) + + override def runTest = afterRendering { + val diagnostics = summon[DocContext].compilerContext.reportedDiagnostics + assertNoWarning(diagnostics) + assertNoErrors(diagnostics) + } From 99d64a755d8454e658d8f240c3be6a67c6450f62 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 2 Jul 2021 17:45:44 +0200 Subject: [PATCH 2/2] Update the no-link-warnings description --- scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala | 2 +- .../dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala index bd7c2a45e503..742d51ee8441 100644 --- a/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala +++ b/scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala @@ -95,7 +95,7 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings: val noLinkWarnings: Setting[Boolean] = BooleanSetting( "-no-link-warnings", - "Avoid warnings for ambiguous and incorrect links ONLY in members look up. Doesn't affect incorrect links of assets etc.", + "Avoid warnings for ambiguous and incorrect links in members look up. Doesn't affect warnings for incorrect links of assets etc.", false ) diff --git a/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala index 3861e63dcdda..1d140315cc10 100644 --- a/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala +++ b/scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala @@ -14,6 +14,6 @@ class LinkWarningsTest extends ScaladocTest("noLinkWarnings"): override def runTest = afterRendering { val diagnostics = summon[DocContext].compilerContext.reportedDiagnostics - assertEquals("There should be exaclyt one warning", 1, diagnostics.warningMsgs.size) + assertEquals("There should be exactly one warning", 1, diagnostics.warningMsgs.size) assertNoErrors(diagnostics) }