Skip to content

Fix warning on missing links from index.html #10589

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

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion scala3doc/src/dotty/dokka/DocContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ val report = dotty.tools.dotc.report
def relativePath(p: Path)(using Context): Path =
val root = Paths.get("").toAbsolutePath()
val absPath = p.toAbsolutePath
println(Seq(p, absPath, absPath.startsWith(root), root.relativize(absPath)))
if absPath.startsWith(root) then root.relativize(p.toAbsolutePath()) else p


Expand Down
13 changes: 8 additions & 5 deletions scala3doc/src/dotty/dokka/site/StaticSiteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,21 @@ class StaticSiteContext(
dir("docs").flatMap(_.listFiles()).flatMap(loadTemplate(_, isBlog = false))
++ dir("blog").flatMap(loadTemplate(_, isBlog = true))

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

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

Seq(baseFile, mdFile).find(Files.exists(_)).map(driFor)
}.toOption.flatten
pathDri.orElse(memberLinkResolver(link))
(Seq(baseFile, mdFile) ++ strippedIndexes).filter(Files.exists(_)).map(driFor)
}.toOption
pathsDri.getOrElse(memberLinkResolver(link).toList)

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

Expand Down
2 changes: 1 addition & 1 deletion scala3doc/src/dotty/dokka/site/common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.jetbrains.dokka.pages._

import scala.collection.JavaConverters._

val docsRootDRI: DRI = mkDRI(extra = "_top_level_index")
val docsRootDRI: DRI = mkDRI("_.docs")
val docsDRI: DRI = mkDRI(extra = "_docs_level_index")
val apiPageDRI: DRI = mkDRI(packageName = "api", extra = "__api__")

Expand Down
13 changes: 5 additions & 8 deletions scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,11 @@ class ScalaHtmlRenderer(using ctx: DokkaContext) extends HtmlRenderer(ctx) {
case HashRegex(path, prefix) => (path, prefix)
case _ => (str, "")

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

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