Skip to content

Commit d8c19be

Browse files
authored
Merge pull request #13917 from dotty-staging/scaladoc/fix-unexisting-links
Fix links to unexisting types sites
2 parents e7f7e19 + 40da3a1 commit d8c19be

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

project/Build.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,11 @@ object Build {
319319

320320
private lazy val currentYear: String = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR).toString
321321

322-
lazy val scalacOptionsDocSettings = Seq(
323-
"-external-mappings:" +
324-
".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," +
325-
".*java/.*::javadoc::https://docs.oracle.com/javase/8/docs/api/",
322+
def scalacOptionsDocSettings(includeExternalMappings: Boolean = true) = {
323+
val extMap = Seq("-external-mappings:" +
324+
(if (includeExternalMappings) ".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," else "") +
325+
".*java/.*::javadoc::https://docs.oracle.com/javase/8/docs/api/")
326+
Seq(
326327
"-skip-by-regex:.+\\.internal($|\\..+)",
327328
"-skip-by-regex:.+\\.impl($|\\..+)",
328329
"-project-logo", "docs/logo.svg",
@@ -340,7 +341,8 @@ object Build {
340341
"-project-footer", s"Copyright (c) 2002-$currentYear, LAMP/EPFL",
341342
"-author",
342343
"-groups"
343-
)
344+
) ++ extMap
345+
}
344346

345347
// Settings used when compiling dotty with a non-bootstrapped dotty
346348
lazy val commonBootstrappedSettings = commonDottySettings ++ NoBloopExport.settings ++ Seq(
@@ -423,7 +425,7 @@ object Build {
423425
assert(docScalaInstance.loaderCompilerOnly == base.loaderCompilerOnly)
424426
docScalaInstance
425427
},
426-
Compile / doc / scalacOptions ++= scalacOptionsDocSettings
428+
Compile / doc / scalacOptions ++= scalacOptionsDocSettings()
427429
)
428430

429431
lazy val commonBenchmarkSettings = Seq(
@@ -1266,7 +1268,7 @@ object Build {
12661268
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
12671269
)
12681270

1269-
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil) =
1271+
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil, includeExternalMappings: Boolean = true) =
12701272
Def.taskDyn {
12711273
val distLocation = (dist / pack).value
12721274
val projectVersion = version.value
@@ -1294,7 +1296,7 @@ object Build {
12941296
dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, "dotty") + "=", "#library/src"),
12951297
dottySrcLink(referenceVersion),
12961298
"-Ygenerate-inkuire",
1297-
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets
1299+
) ++ scalacOptionsDocSettings(includeExternalMappings) ++ revision ++ params ++ targets
12981300
import _root_.scala.sys.process._
12991301
val escapedCmd = cmd.map(arg => if(arg.contains(" ")) s""""$arg"""" else arg)
13001302
Def.task {
@@ -1424,7 +1426,7 @@ object Build {
14241426
"https://scala-lang.org/api/versions.json",
14251427
"-Ydocument-synthetic-types",
14261428
s"-snippet-compiler:${dottyLibRoot}/scala/quoted=compile,${dottyLibRoot}/scala/compiletime=compile"
1427-
) ++ (if (justAPI) Nil else Seq("-siteroot", "docs-for-dotty-page", "-Yapi-subdirectory")))
1429+
) ++ (if (justAPI) Nil else Seq("-siteroot", "docs-for-dotty-page", "-Yapi-subdirectory")), includeExternalMappings = false)
14281430

14291431
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
14301432
else if (justAPI) generateDocTask

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,21 @@ trait ClassLikeSupport:
7070
case tree: ClassDef => tree
7171
case tt: TypeTree => unpackTreeToClassDef(tt.tpe.typeSymbol.tree)
7272

73-
def getSupertypesGraph(classDef: Tree, link: LinkToType): Seq[(LinkToType, LinkToType)] =
74-
val smbl = classDef.symbol
75-
val parents = unpackTreeToClassDef(classDef).parents
76-
parents.flatMap { case tree =>
73+
def getSupertypesGraph(link: LinkToType, to: Seq[Tree]): Seq[(LinkToType, LinkToType)] =
74+
to.flatMap { case tree =>
7775
val symbol = if tree.symbol.isClassConstructor then tree.symbol.owner else tree.symbol
7876
val superLink = LinkToType(tree.asSignature, symbol.dri, bareClasslikeKind(symbol))
79-
Seq(link -> superLink) ++ getSupertypesGraph(tree, superLink)
77+
val nextTo = unpackTreeToClassDef(tree).parents
78+
if symbol.isHiddenByVisibility then getSupertypesGraph(link, nextTo)
79+
else Seq(link -> superLink) ++ getSupertypesGraph(superLink, nextTo)
8080
}
8181

82-
val supertypes = getSupertypes(using qctx)(classDef).map {
83-
case (symbol, tpe) =>
84-
LinkToType(tpe.asSignature, symbol.dri, bareClasslikeKind(symbol))
85-
}
82+
val supertypes = getSupertypes(using qctx)(classDef)
83+
.filterNot((s, t) => s.isHiddenByVisibility)
84+
.map {
85+
case (symbol, tpe) =>
86+
LinkToType(tpe.asSignature, symbol.dri, bareClasslikeKind(symbol))
87+
}
8688
val selfType = classDef.self.map { (valdef: ValDef) =>
8789
val symbol = valdef.symbol
8890
val tpe = valdef.tpt.tpe
@@ -91,7 +93,7 @@ trait ClassLikeSupport:
9193
val selfSignature: DSignature = typeForClass(classDef).asSignature
9294

9395
val graph = HierarchyGraph.withEdges(
94-
getSupertypesGraph(classDef, LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
96+
getSupertypesGraph(LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)), unpackTreeToClassDef(classDef).parents)
9597
)
9698

9799
val baseMember = mkMember(classDef.symbol, kindForClasslike(classDef), selfSignature)(
@@ -255,7 +257,7 @@ trait ClassLikeSupport:
255257
case t: TypeTree => t.tpe.typeSymbol
256258
case tree if tree.symbol.isClassConstructor => tree.symbol.owner
257259
case tree => tree.symbol
258-
if parentSymbol != defn.ObjectClass && parentSymbol != defn.AnyClass
260+
if parentSymbol != defn.ObjectClass && parentSymbol != defn.AnyClass && !parentSymbol.isHiddenByVisibility
259261
yield (parentTree, parentSymbol)
260262

261263
def getConstructors: List[Symbol] = c.membersToDocument.collect {

scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ trait TypesSupport:
6161
extension (on: SignaturePart) def l: List[SignaturePart] = List(on)
6262

6363
private def tpe(using Quotes)(symbol: reflect.Symbol): SSignature =
64+
import SymOps._
6465
val suffix = if symbol.isValDef || symbol.flags.is(reflect.Flags.Module) then plain(".type").l else Nil
65-
dotty.tools.scaladoc.Type(symbol.normalizedName, Some(symbol.dri)) :: suffix
66+
val dri: Option[DRI] = Option(symbol).filterNot(_.isHiddenByVisibility).map(_.dri)
67+
dotty.tools.scaladoc.Type(symbol.normalizedName, dri) :: suffix
6668

6769
private def commas(lists: List[SSignature]) = lists match
6870
case List(single) => single

0 commit comments

Comments
 (0)