Skip to content

Fix various small bugs in scaladoc #12926

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
Jun 24, 2021
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
2 changes: 1 addition & 1 deletion docs/docs/usage/scaladoc/site-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ doc / scalacOptions ++= Seq("-versions-dictionary-url", "https://dotty.epfl.ch/v

Providing a JSON file via `-versions-dictionary-url` enables scaladoc to link between versions. It is also convenient to be able to change the revision label in the drop-down menu. Everything will change automatically.

![](../../../images/scaladoc/nightly.gif)
![](images/scaladoc/nightly.gif)
4 changes: 2 additions & 2 deletions scaladoc/resources/dotty_res/styles/scalastyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ th {
#logo>span>img {
max-height: 40px;
max-width: 40px;
padding: 16px 8px 8px 16px;
margin: 16px 8px 8px 16px;
cursor: pointer;
}

Expand Down Expand Up @@ -1011,4 +1011,4 @@ footer .socials {

.breadcrumbs a:first-child {
margin: 0 8px 0 0;
}
}
13 changes: 7 additions & 6 deletions scaladoc/src/dotty/tools/scaladoc/SourceLinks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def pathToString(p: Path) =

trait SourceLink:
val path: Option[Path] = None
def render(memberName: String, path: Path, operation: String, line: Option[Int]): String
def render(memberName: String, path: Path, operation: String, line: Option[Int], optionalRevision: Option[String]): String

case class TemplateSourceLink(val urlTemplate: String) extends SourceLink:
override val path: Option[Path] = None
override def render(memberName: String, path: Path, operation: String, line: Option[Int]): String =
override def render(memberName: String, path: Path, operation: String, line: Option[Int], optionalRevision: Option[String]): String =
val pathString = "/" + pathToString(path)
val mapping = Map(
"\\{\\{ path \\}\\}".r -> pathString,
Expand All @@ -36,10 +36,11 @@ case class TemplateSourceLink(val urlTemplate: String) extends SourceLink:

case class WebBasedSourceLink(prefix: String, revision: String, subPath: String) extends SourceLink:
override val path: Option[Path] = None
override def render(memberName: String, path: Path, operation: String, line: Option[Int]): String =
override def render(memberName: String, path: Path, operation: String, line: Option[Int], optionalRevision: Option[String] = None): String =
val action = if operation == "view" then "blob" else operation
val finalRevision = optionalRevision.getOrElse(revision)
val linePart = line.fold("")(l => s"#L$l")
s"$prefix/$action/$revision$subPath/${pathToString(path)}$linePart"
s"$prefix/$action/$finalRevision$subPath/${pathToString(path)}$linePart"

class SourceLinkParser(revision: Option[String]) extends ArgParser[SourceLink]:
val KnownProvider = raw"(\w+):\/\/([^\/#]+)\/([^\/#]+)(\/[^\/#]+)?(#.+)?".r
Expand Down Expand Up @@ -97,8 +98,8 @@ class SourceLinkParser(revision: Option[String]) extends ArgParser[SourceLink]:
type Operation = "view" | "edit"

class SourceLinks(val sourceLinks: PathBased[SourceLink]):
def pathTo(rawPath: Path, memberName: String = "", line: Option[Int] = None, operation: Operation = "view"): Option[String] =
sourceLinks.get(rawPath).map(res => res.elem.render(memberName, res.path, operation, line))
def pathTo(rawPath: Path, memberName: String = "", line: Option[Int] = None, operation: Operation = "view", optionalRevision: Option[String] = None): Option[String] =
sourceLinks.get(rawPath).map(res => res.elem.render(memberName, res.path, operation, line, optionalRevision))

def pathTo(member: Member): Option[String] =
member.sources.flatMap(s => pathTo(s.path, member.name, Option(s.lineNumber).map(_ + 1)))
Expand Down
5 changes: 2 additions & 3 deletions scaladoc/src/dotty/tools/scaladoc/renderers/Locations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ trait Locations(using ctx: DocContext):
cache.get(dri) match
case null =>
val path = dri match
case `docsDRI` => List("docs", "index")
case `docsRootDRI` => List("index")
case `docsRootDRI` => List("docs", "index")
case `apiPageDRI` => List("api", "index")
case dri if dri.isStaticFile =>
Paths.get(dri.location).iterator.asScala.map(_.toString).toList
case dri =>
val loc = dri.location
val fqn = loc.split(Array('.')).toList match
case "<empty>" :: Nil => "_empty_" :: Nil
case "<empty>" :: Nil => "_empty_" :: Nil
case "<empty>" :: tail => "_empty_" :: tail
case other => other

Expand Down
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/renderers/Writer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ trait Writer(using ctx: DocContext) extends Locations:

def copy(from: InputStream, to: String): String =
Files.copy(from, dest(to))
to
to
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ case class LoadedTemplate(
// toRealPath is used to turn symlinks into proper paths
val actualPath = Paths.get("").toAbsolutePath.relativize(file.toPath.toRealPath())
ctx.sourceLinks.pathTo(actualPath).map("viewSource" -> _ ) ++
ctx.sourceLinks.pathTo(actualPath, operation = "edit").map("editSource" -> _ )
ctx.sourceLinks.pathTo(actualPath, operation = "edit", optionalRevision = Some("master")).map("editSource" -> _ )

val updatedSettings = templateFile.settings ++ ctx.projectWideProperties +
("site" -> (getMap("site") + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap) +
Expand Down
3 changes: 1 addition & 2 deletions scaladoc/src/dotty/tools/scaladoc/site/common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension

import scala.collection.JavaConverters._

val docsRootDRI: DRI = DRI(location = "index.md")
val docsDRI: DRI = DRI(location = "docs/index.md")
val docsRootDRI: DRI = DRI(location = "docs", symbolUUID = staticFileSymbolUUID)
val apiPageDRI: DRI = DRI(location = "api")

val defaultMarkdownOptions: DataHolder =
Expand Down
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/site/templates.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ case class TemplateFile(
layoutTemplate match
case None => ResolvedPage(code, resources ++ ctx.resources)
case Some(layoutTemplate) =>
layoutTemplate.resolveInner(ctx.nest(code, file, resources))
layoutTemplate.resolveInner(ctx.nest(code, file, resources))