Skip to content
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

Tweak Language Reference documentation #14669

Merged
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/_blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h1>{{ page.title }}</h1>

<ul class="post-list">
{% for post in site.posts %}
{% for post in site.subpages %}
<li>
<h2>
<a href="{{ post.url }}">{{ post.title }}</a>
Expand Down
4 changes: 4 additions & 0 deletions docs/_docs/contributing/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: index
title: Contributing
---
8 changes: 2 additions & 6 deletions docs/_docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: doc-page
redirectFrom: docs/index.html
layout: index
redirectFrom: /docs/index.html
---

Dotty is the project name for technologies that are considered for inclusion in Scala 3. Scala has
Expand All @@ -16,7 +16,3 @@ be a big step towards realizing the full potential of these ideas. Its main obje
In this documentation you will find information on how to use the Dotty compiler on your machine,
navigate through the code, setup Dotty with your favorite IDE and more!

Table of Contents
=================
{% assign titles = sidebar.titles %}
{% include "table-of-contents" %}
5 changes: 5 additions & 0 deletions docs/_docs/internals/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: index
title: Internals
---

2 changes: 1 addition & 1 deletion docs/_docs/reference/changed-features/changed-features.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Other Changed Features"
movedTo: https://docs.scala-lang.org/scala3/reference/changed-features.html
---
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/contextual/contextual.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Contextual Abstractions"
movedTo: https://docs.scala-lang.org/scala3/reference/contextual.html
---
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/dropped-features/dropped-features.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Dropped Features"
movedTo: https://docs.scala-lang.org/scala3/reference/dropped-features.html
---
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/enums/enums-index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Enums"
movedTo: https://docs.scala-lang.org/scala3/reference/enums.html
---
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/experimental/named-typeargs.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: doc-page
title: "Named Type Arguments"
redirectFrom: reference/other-new-features/named-typeargs.html
redirectFrom: /docs/reference/other-new-features/named-typeargs.html
movedTo: https://docs.scala-lang.org/scala3/reference/experimental/named-typeargs.html
---

Expand Down
3 changes: 2 additions & 1 deletion docs/_docs/reference/experimental/overview.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: doc-page
title: "Overview"
title: "Experimental"
movedTo: https://docs.scala-lang.org/scala3/reference/experimental/overview.html
redirectFrom: overview.html
---

### Experimental language features
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Language Versions"
---

Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/metaprogramming/metaprogramming.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Metaprogramming"
movedTo: https://docs.scala-lang.org/scala3/reference/metaprogramming.html
---
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/new-types/new-types.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "New Types"
movedTo: https://docs.scala-lang.org/scala3/reference/new-types.html
---
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/other-new-features/other-new-types.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Other New Features"
movedTo: https://docs.scala-lang.org/scala3/reference/other-new-features.html
---
Expand Down
3 changes: 2 additions & 1 deletion docs/_docs/reference/overview.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: doc-page
title: "Overview"
title: "Reference"
movedTo: https://docs.scala-lang.org/scala3/reference/overview.html
redirectFrom: overview.html
---

Scala 3 implements many language changes and improvements over Scala 2.
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/usage/dottydoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ An example of this would be:
To be rendered as templates, each blog post should have front-matter and a
`layout` declaration.

The posts are also available in the variable `site.posts` throughout the site.
The posts are also available in the variable `site.subpages` throughout the site.
The fields of these objects are the same as in
`[BlogPost](dotty.tools.dottydoc.staticsite.BlogPost)`.

Expand Down
4 changes: 4 additions & 0 deletions docs/_docs/usage/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: index
title: Usage
---
2 changes: 1 addition & 1 deletion docs/_docs/usage/scaladoc/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: doc-page
layout: index
title: "Scaladoc"
---

Expand Down
15 changes: 13 additions & 2 deletions docs/_layouts/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
layout: main
layout: static-site-main
---
<h1>{{ content }}</h1>
<h1>{{ page.title }}</h1>

{{ content }}

<h2>Table of Contents</h2>
<ul class="table-of-contents">
{% for subpage in site.subpages %}
<li>
<a href="{{ subpage.url }}">{{ subpage.title }}</a>
</li>
{% endfor %}
</ul>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

7 changes: 5 additions & 2 deletions docs/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ index: index.md
subsection:
- title: Usage
directory: docs/usage
index: usage/index.md
subsection:
- page: usage/sbt-projects.md
- page: usage/ide-support.md
Expand All @@ -17,8 +18,8 @@ subsection:
- page: usage/scaladoc/static-site.md
- title: Reference
directory: docs/reference
index: reference/overview.md
subsection:
- page: reference/overview.md
- title: New Types
index: reference/new-types/new-types.md
subsection:
Expand Down Expand Up @@ -137,8 +138,8 @@ subsection:
- page: reference/dropped-features/wildcard-init.md
- title: Experimental Features
directory: experimental
index: reference/experimental/overview.md
subsection:
- page: reference/experimental/overview.md
- page: reference/experimental/canthrow.md
- page: reference/experimental/erased-defs.md
- page: reference/experimental/erased-defs-spec.md
Expand All @@ -157,6 +158,7 @@ subsection:
- page: reference/features-classification.md
- title: Contributing
directory: docs/contributing
index: contributing/index.md
subsection:
- page: contributing/contribute-knowledge.md
- page: contributing/getting-started.md
Expand All @@ -175,6 +177,7 @@ subsection:
- page: contributing/procedures/vulpix.md
- title: Internals
directory: docs/internals
index: internals/index.md
subsection:
- page: internals/backend.md
- page: internals/classpaths.md
Expand Down
1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ object Build {
.add(OutputDir("scaladoc/output/reference"))
.add(SiteRoot(s"${temp.getAbsolutePath}/docs"))
.add(ProjectName("Scala 3 Reference"))
.remove[VersionsDictionaryUrl]
.add(SourceLinks(List(
dottySrcLink(referenceVersion, temp.getAbsolutePath + "=")
)))
Expand Down
5 changes: 2 additions & 3 deletions project/resources/referenceReplacements/sidebar.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
index: reference/overview.md
subsection:
- page: reference/overview.md
- title: New Types
index: reference/new-types/new-types.md
subsection:
Expand Down Expand Up @@ -119,8 +118,8 @@ subsection:
- page: reference/dropped-features/wildcard-init.md
- title: Experimental Features
directory: experimental
index: reference/experimental/overview.md
subsection:
- page: reference/experimental/overview.md
- page: reference/experimental/canthrow.md
- page: reference/experimental/erased-defs.md
- page: reference/experimental/erased-defs-spec.md
Expand All @@ -136,4 +135,4 @@ subsection:
- page: reference/language-versions/source-compatibility.md
- page: reference/language-versions/binary-compatibility.md
- page: reference/soft-modifier.md
- page: reference/features-classification.md
- page: reference/features-classification.md
2 changes: 1 addition & 1 deletion scaladoc-js/common/src/code-snippets/CodeSnippets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CodeSnippets:
val buttonsSection = getButtonsSection(snippet)
buttonsSection.foreach(s =>
s.appendChild(copyButton)
if !snippet.hasAttribute("hasContext") then {
if snippet.hasAttribute("runnable") then {
s.appendChild(toScastieButton)
s.appendChild(runButton)
s.appendChild(exitButton)
Expand Down
4 changes: 2 additions & 2 deletions scaladoc-testcases/docs/_docs/docs/f1.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: static-site-main
redirectFrom:
- docs/fr.html
- docs/my-custom-link
- /docs/fr.html
- /docs/my-custom-link
---
F1
4 changes: 2 additions & 2 deletions scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ case class LoadedTemplate(
)

def resolveToHtml(ctx: StaticSiteContext): ResolvedPage =
val posts = children.map(_.lazyTemplateProperties(ctx))
val subpages = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx))
def getMap(key: String) = templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]]

val sourceLinks = if !file.exists() then Nil else
Expand All @@ -50,7 +50,7 @@ case class LoadedTemplate(
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) +
("site" -> (getMap("site") + ("subpages" -> subpages))) + ("urls" -> sourceLinks.toMap) +
("page" -> (getMap("page") + ("title" -> templateFile.title.name)))

templateFile.resolveInner(RenderingContext(updatedSettings, ctx.layouts))(using ctx)
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ class StaticSiteContext(
allTemplates.flatMap { loadedTemplate =>
val redirectFrom = loadedTemplate.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]].get("redirectFrom")
def redirectToTemplate(redirectFrom: String) =
val fakeFile = new File(docsPath.toFile, redirectFrom)
val driFrom = driFor(fakeFile.toPath)
val path = if redirectFrom.startsWith("/")
then relativizeFrom.resolve(redirectFrom.drop(1))
else loadedTemplate.file.toPath.resolveSibling(redirectFrom)
val driFrom = driFor(path)
val driTo = driFor(loadedTemplate.file.toPath)
(LoadedTemplate(layouts("redirect"), List.empty, fakeFile), driFrom, driTo)
(LoadedTemplate(layouts("redirect"), List.empty, path.toFile), driFrom, driTo)
redirectFrom.map {
case redirectFrom: String => Seq(redirectToTemplate(redirectFrom))
case redirects: List[?] => redirects.asInstanceOf[List[String]].map(redirectToTemplate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.vladsch.flexmark.html._
import util.HTML._

import dotty.tools.scaladoc.snippets._
import dotty.tools.scaladoc.util.HTML._

case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty, attributes: Map[String, String] = Map.empty):
def withClass(cls: String) = this.copy(classes = classes + cls)
Expand Down Expand Up @@ -134,15 +133,26 @@ object SnippetRenderer:
div(cls := "snippet-label")(name)
).toString

def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String =
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): String =
val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML)
val codeHTML = s"""<code class="language-scala">${transformedLines.mkString("")}</code>"""
s"""<div class="snippet" scala-snippet ${if hasContext then "hasContext" else ""}><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
val isRunnable = !hasContext && success
val attrs = Seq(
Option.when(isRunnable)(Attr("runnable") := "")
).flatten
div(cls := "snippet", Attr("scala-snippet") := "", attrs)(
div(cls := "buttons")(),
pre(
raw(codeHTML)
),
raw(snippetName.fold("")(snippetLabel(_)))
).toString

def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String =
renderSnippetWithMessages(
node.name,
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
node.compilationResult.toSeq.flatMap(_.messages),
node.hasContext
node.hasContext,
node.compilationResult.fold(false)(_.isSuccessful)
)