Skip to content

Commit 61b53ec

Browse files
authored
Merge pull request #15132 from lampepfl/language-reference-backport
Backport changes from stable documentation branch
2 parents e099a8b + bf78721 commit 61b53ec

File tree

12 files changed

+34
-18
lines changed

12 files changed

+34
-18
lines changed

.github/workflows/language-reference.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
uses: actions/checkout@v3
2222
with:
2323
path: 'dotty'
24-
ref: 'language-reference-stable'
2524
fetch-depth: 0
2625
ssh-key: ${{ secrets.DOCS_KEY }}
2726

docs/sidebar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ subsection:
6969
- page: reference/metaprogramming/reflection.md
7070
- page: reference/metaprogramming/tasty-inspect.md
7171
- title: Other New Features
72-
index: reference/other-new-features/other-new-types.md
72+
index: reference/other-new-features/other-new-features.md
7373
subsection:
7474
- page: reference/other-new-features/trait-parameters.md
7575
- page: reference/other-new-features/transparent-traits.md

project/Build.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,21 +1381,33 @@ object Build {
13811381
generateDocumentation(Testcases)
13821382
}.value,
13831383

1384+
// Generate the Scala 3 reference documentation (published at https://docs.scala-lang.org/scala3/reference)
13841385
generateReferenceDocumentation := Def.inputTaskDyn {
13851386
val shouldRegenerateExpectedLinks = (Space ~> literal("--no-regenerate-expected-links")).?.parsed.isEmpty
13861387

13871388
generateStaticAssetsTask.value
13881389

1390+
// Move all the source files to a temporary directory and apply some changes specific to the reference documentation
13891391
val temp = IO.createTemporaryDirectory
13901392
IO.copyDirectory(file("docs"), temp / "docs")
13911393
IO.delete(temp / "docs" / "_blog")
13921394

1395+
// Overwrite the main layout and the sidebar
13931396
IO.copyDirectory(
13941397
file("project") / "resources" / "referenceReplacements",
13951398
temp / "docs",
13961399
overwrite = true
13971400
)
13981401

1402+
// Add redirections from previously supported URLs, for some pages
1403+
for (name <- Seq("changed-features", "contextual", "dropped-features", "metaprogramming", "other-new-features")) {
1404+
val path = temp / "docs" / "_docs" / "reference" / name / s"${name}.md"
1405+
val contentLines = IO.read(path).linesIterator.to[collection.mutable.ArrayBuffer]
1406+
contentLines.insert(1, s"redirectFrom: /${name}.html") // Add redirection
1407+
val newContent = contentLines.mkString("\n")
1408+
IO.write(path, newContent)
1409+
}
1410+
13991411
val languageReferenceConfig = Def.task {
14001412
Scala3.value
14011413
.add(OutputDir("scaladoc/output/reference"))
@@ -1404,7 +1416,7 @@ object Build {
14041416
.add(ProjectVersion("3.1.2")) // TODO: Change that later to the current version tag. (This must happen on first forward this branch to stable release tag)
14051417
.remove[VersionsDictionaryUrl]
14061418
.add(SourceLinks(List(
1407-
dottySrcLink(referenceVersion, temp.getAbsolutePath + "=")
1419+
dottySrcLink("language-reference-stable", temp.getAbsolutePath + "=")
14081420
)))
14091421
.withTargets(List("___fake___.scala"))
14101422
}

project/resources/referenceReplacements/sidebar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ subsection:
4949
- page: reference/metaprogramming/reflection.md
5050
- page: reference/metaprogramming/tasty-inspect.md
5151
- title: Other New Features
52-
index: reference/other-new-features/other-new-types.md
52+
index: reference/other-new-features/other-new-features.md
5353
subsection:
5454
- page: reference/other-new-features/trait-parameters.md
5555
- page: reference/other-new-features/transparent-traits.md

project/scripts/docsLinksStability

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXPECTED_LINKS_FILE=$2 # The location of expected-links.txt is passed as a secon
99

1010
pushd $DOCS_DIR > /dev/null # Go to docs dir but remember previous location
1111
# We need to go to docs dir to make find return correct relative paths
12-
find . -type f -name "*.html" | sort | (popd > /dev/null; diff $EXPECTED_LINKS_FILE -;)
12+
find . -type f -name "*.html" | LC_ALL=C sort | (popd > /dev/null; diff $EXPECTED_LINKS_FILE -;)
1313
# We list every html file in documentation, then sort it and finally compare to the expected links list.
1414
# Before running diff we need to popd to return to the previous location because we don't have relative path to the expected links file.
1515

project/scripts/expected-links/reference-expected-links.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
./changed-features.html
12
./changed-features/compiler-plugins.html
23
./changed-features/eta-expansion-spec.html
34
./changed-features/eta-expansion.html
@@ -20,6 +21,7 @@
2021
./changed-features/type-inference.html
2122
./changed-features/vararg-splices.html
2223
./changed-features/wildcards.html
24+
./contextual.html
2325
./contextual/by-name-context-parameters.html
2426
./contextual/context-bounds.html
2527
./contextual/context-functions-spec.html
@@ -38,6 +40,7 @@
3840
./contextual/using-clauses.html
3941
./docs/reference/other-new-features/named-typeargs.html
4042
./docsScalaLangResources/scaladoc-assets.html
43+
./dropped-features.html
4144
./dropped-features/auto-apply.html
4245
./dropped-features/class-shadowing-spec.html
4346
./dropped-features/class-shadowing.html
@@ -78,6 +81,7 @@
7881
./language-versions/binary-compatibility.html
7982
./language-versions/index.html
8083
./language-versions/source-compatibility.html
84+
./metaprogramming.html
8185
./metaprogramming/compiletime-ops.html
8286
./metaprogramming/index.html
8387
./metaprogramming/inline.html
@@ -97,6 +101,7 @@
97101
./new-types/type-lambdas.html
98102
./new-types/union-types-spec.html
99103
./new-types/union-types.html
104+
./other-new-features.html
100105
./other-new-features/control-syntax.html
101106
./other-new-features/creator-applications.html
102107
./other-new-features/experimental-defs.html

project/scripts/regenerateExpectedLinks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXPECTED_LINKS_FILE=$2 # The location of expected-links.txt is passed as a secon
99

1010
pushd $DOCS_DIR > /dev/null # Go to docs dir but remember previous location
1111
# We need to go to docs dir to make find return correct relative paths
12-
find . -type f -name "*.html" | (popd > /dev/null; sort > $2;)
12+
find . -type f -name "*.html" | (popd > /dev/null; LC_ALL=C sort > $2;)
1313
# We list every html file in documentation, then sort it and finally write it to the expected links list file.
1414
# Before writing we need to popd to return to the previous location because we don't have relative path to the expected links file.
1515

scaladoc/src/dotty/tools/scaladoc/DocContext.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@ case class DocContext(args: Scaladoc.Args, compilerContext: CompilerContext):
103103
report.warning(
104104
s"""Following generated file paths might not be compatible with Jekyll:
105105
|${jekyllIncompatLinks.mkString("\n")}
106-
|If using GitHub Pages consider adding a \".nojekyll\" file.
107-
""".stripMargin)(using compilerContext)
106+
|If using GitHub Pages consider adding a \".nojekyll\" file.""".stripMargin
107+
)(using compilerContext)

scaladoc/src/dotty/tools/scaladoc/PathBased.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import java.nio.file.{Path, Paths}
44

55
case class PathBased[T](entries: List[PathBased.Entry[T]], projectRoot: Path):
66
def get(path: Path): Option[PathBased.Result[T]] =
7-
if path.isAbsolute && path.startsWith(projectRoot) then get(projectRoot.relativize(path))
8-
else entries.filter(_.path.forall(p => path.startsWith(p))).maxByOption(_.path.map(_.toString.length)).map(entry =>
9-
PathBased.Result(entry.path.fold(path)(_.relativize(path)), entry.elem)
10-
)
7+
val paths = Option.when(path.isAbsolute && path.startsWith(projectRoot))(projectRoot.relativize(path)).toSeq :+ path
8+
paths.iterator.to(LazyList).flatMap { path =>
9+
entries.filter(_.path.forall(p => path.startsWith(p))).maxByOption(_.path.map(_.toString.length)).map(entry =>
10+
PathBased.Result(entry.path.fold(path)(_.relativize(path)), entry.elem)
11+
)
12+
}.headOption
1113

1214
trait ArgParser[T]:
1315
def parse(s: String): Either[String, T]

scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
223223
footer(
224224
div(id := "generated-by")(
225225
span(cls := "footer-text")(raw("Generated by")),
226-
a(href := "https://github.com/lampepfl/dotty/tree/master/scaladoc")(
226+
a(href := "https://github.com/lampepfl/dotty/tree/main/scaladoc")(
227227
img(
228228
src := resolveRoot(link.dri, "images/scaladoc_logo.svg"),
229229
alt := "scaladoc",

scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ case class LoadedTemplate(
4242
val subpages = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx))
4343
def getMap(key: String) = templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]]
4444

45-
val sourceLinks = if !file.exists() then Nil else
46-
// TODO (https://github.com/lampepfl/scala3doc/issues/240): configure source root
47-
// toRealPath is used to turn symlinks into proper paths
48-
val actualPath = Paths.get("").toAbsolutePath.relativize(file.toPath.toRealPath())
45+
val sourceLinks = if !templateFile.file.exists() then Nil else
46+
val actualPath = templateFile.file.toPath
4947
ctx.sourceLinks.pathTo(actualPath).map("viewSource" -> _ ) ++
50-
ctx.sourceLinks.pathTo(actualPath, operation = "edit", optionalRevision = Some("master")).map("editSource" -> _)
48+
ctx.sourceLinks.pathTo(actualPath, operation = "edit").map("editSource" -> _)
5149

5250
val updatedSettings = templateFile.settings ++ ctx.projectWideProperties +
5351
("site" -> (getMap("site") + ("subpages" -> subpages))) + ("urls" -> sourceLinks.toMap) +

0 commit comments

Comments
 (0)