Skip to content

Commit c5d44fc

Browse files
authored
Merge pull request #10589 from romanowski/scala3doc/clean-up-warnings
Fix warning on missing links from index.html
2 parents e0c6e6f + 440a0d9 commit c5d44fc

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

scala3doc/src/dotty/dokka/DocContext.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ val report = dotty.tools.dotc.report
3232
def relativePath(p: Path)(using Context): Path =
3333
val root = Paths.get("").toAbsolutePath()
3434
val absPath = p.toAbsolutePath
35-
println(Seq(p, absPath, absPath.startsWith(root), root.relativize(absPath)))
3635
if absPath.startsWith(root) then root.relativize(p.toAbsolutePath()) else p
3736

3837

scala3doc/src/dotty/dokka/site/StaticSiteContext.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,21 @@ class StaticSiteContext(
150150
dir("docs").flatMap(_.listFiles()).flatMap(loadTemplate(_, isBlog = false))
151151
++ dir("blog").flatMap(loadTemplate(_, isBlog = true))
152152

153-
def driForLink(template: TemplateFile, link: String): Option[DRI] =
154-
val pathDri = Try {
153+
def driForLink(template: TemplateFile, link: String): Seq[DRI] =
154+
val pathsDri: Option[Seq[DRI]] = Try {
155155
val baseFile =
156156
if link.startsWith("/") then root.toPath.resolve(link.drop(1))
157157
else template.file.toPath.getParent().resolve(link).normalize()
158158

159159
val baseFileName = baseFile.getFileName.toString
160160
val mdFile = baseFile.resolveSibling(baseFileName.stripSuffix(".html") + ".md")
161+
def trySuffix(pref: String) =
162+
if baseFileName == pref then Seq(baseFile.getParent) else Nil
163+
val strippedIndexes = trySuffix("index.html") ++ trySuffix("index.md")
161164

162-
Seq(baseFile, mdFile).find(Files.exists(_)).map(driFor)
163-
}.toOption.flatten
164-
pathDri.orElse(memberLinkResolver(link))
165+
(Seq(baseFile, mdFile) ++ strippedIndexes).filter(Files.exists(_)).map(driFor)
166+
}.toOption
167+
pathsDri.getOrElse(memberLinkResolver(link).toList)
165168

166169
def driFor(dest: Path): DRI = mkDRI(s"_.${root.toPath.relativize(dest)}")
167170

scala3doc/src/dotty/dokka/site/common.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.jetbrains.dokka.pages._
2222

2323
import scala.collection.JavaConverters._
2424

25-
val docsRootDRI: DRI = mkDRI(extra = "_top_level_index")
25+
val docsRootDRI: DRI = mkDRI("_.docs")
2626
val docsDRI: DRI = mkDRI(extra = "_docs_level_index")
2727
val apiPageDRI: DRI = mkDRI(packageName = "api", extra = "__api__")
2828

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,11 @@ class ScalaHtmlRenderer(using ctx: DokkaContext) extends HtmlRenderer(ctx) {
260260
case HashRegex(path, prefix) => (path, prefix)
261261
case _ => (str, "")
262262

263-
// TODO (https://github.com/lampepfl/scala3doc/issues/238) proper warnings about unresolved links
264-
prc.context.driForLink(prc.template.templateFile, path)
265-
.flatMap(dri => Option(getLocationProvider.resolve(dri, sourceSets, page)))
266-
.map(_ + prefix)
267-
.getOrElse {
268-
report.warn(s"Unable to resolve link '$str'", prc.template.file)
269-
str
270-
}
263+
val dri = prc.context.driForLink(prc.template.templateFile, path)
264+
val res = dri.flatMap(dri => Option(getLocationProvider.resolve(dri, sourceSets, page)))
265+
if res.isEmpty then
266+
report.warn(s"Unable to resolve link '$str'", prc.template.file)
267+
res.headOption.fold(str)(_ + prefix)
271268

272269
def processLocalLink(str: String): String =
273270
if str.startsWith("#") || str.isEmpty then str

0 commit comments

Comments
 (0)