Skip to content

Commit 689625d

Browse files
authored
Update user manual for scaladoc (#12083)
Update user manual for scaladoc
1 parent 8f3fdf5 commit 689625d

File tree

19 files changed

+523
-81
lines changed

19 files changed

+523
-81
lines changed

NOTICE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ major authors were omitted by oversight.
8282
modifications. They were originally authored by Lex Spoon, Som Snytt,
8383
Adriaan Moors, Paul Phillips and others.
8484

85-
* dotty.tools.dottydoc: The Dottydoc documentation utility ships some
85+
* dotty.tools.scaladoc: The Scaladoc documentation utility ships some
8686
third-party JavaScript and CSS libraries which are located under
87-
dotty-doc/resources/css/, dotty-doc/resources/js/, docs/css/ and
87+
scaladoc/resources/dotty_res/styles/, scaladoc/resources/dotty_res/scripts/, docs/css/ and
8888
docs/js/. Please refer to the license header of the concerned files for
8989
details.
9090

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object Printers {
2020
val debug = noPrinter
2121
val derive = noPrinter
2222
val desugar = noPrinter
23-
val dottydoc = noPrinter
23+
val scaladoc = noPrinter
2424
val exhaustivity = noPrinter
2525
val gadts = noPrinter
2626
val gadtsConstr = noPrinter

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ trait AllScalaSettings extends CommonScalaSettings { self: Settings.SettingGroup
214214

215215
val YforceInlineWhileTyping: Setting[Boolean] = BooleanSetting("-Yforce-inline-while-typing", "Make non-transparent inline methods inline when typing. Emulates the old inlining behavior of 3.0.0-M3.")
216216

217-
/** Dottydoc specific settings that are not used in scaladoc */
218-
val docSnapshot: Setting[Boolean] = BooleanSetting("-doc-snapshot", "Generate a documentation snapshot for the current Dotty version")
219-
220217
val projectUrl: Setting[String] = StringSetting (
221218
"-project-url",
222219
"project repository homepage",

compiler/src/dotty/tools/dotc/core/Comments.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ object Comments {
143143
* @author Felix Mulder
144144
*/
145145
class CommentExpander {
146-
import dotc.config.Printers.dottydoc
146+
import dotc.config.Printers.scaladoc
147147
import scala.collection.mutable
148148

149149
def expand(sym: Symbol, site: Symbol)(using Context): String = {
@@ -203,7 +203,7 @@ object Comments {
203203
case None =>
204204
// SI-8210 - The warning would be false negative when this symbol is a setter
205205
if (ownComment.indexOf("@inheritdoc") != -1 && ! sym.isSetter)
206-
dottydoc.println(s"${sym.span}: the comment for ${sym} contains @inheritdoc, but no parent comment is available to inherit from.")
206+
scaladoc.println(s"${sym.span}: the comment for ${sym} contains @inheritdoc, but no parent comment is available to inherit from.")
207207
ownComment.replace("@inheritdoc", "<invalid inheritdoc annotation>")
208208
case Some(sc) =>
209209
if (ownComment == "") sc
@@ -317,7 +317,7 @@ object Comments {
317317
val sectionTextBounds = extractSectionText(parent, section)
318318
cleanupSectionText(parent.substring(sectionTextBounds._1, sectionTextBounds._2))
319319
case None =>
320-
dottydoc.println(s"""${sym.span}: the """" + getSectionHeader + "\" annotation of the " + sym +
320+
scaladoc.println(s"""${sym.span}: the """" + getSectionHeader + "\" annotation of the " + sym +
321321
" comment contains @inheritdoc, but the corresponding section in the parent is not defined.")
322322
"<invalid inheritdoc annotation>"
323323
}
@@ -384,7 +384,7 @@ object Comments {
384384
lookupVariable(vname, site) match {
385385
case Some(replacement) => replaceWith(replacement)
386386
case None =>
387-
dottydoc.println(s"Variable $vname undefined in comment for $sym in $site")
387+
scaladoc.println(s"Variable $vname undefined in comment for $sym in $site")
388388
}
389389
}
390390
}

compiler/src/dotty/tools/dotc/util/CommentParsing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ package dotty.tools.dotc.util
88
import scala.collection.mutable
99

1010
/** The comment parsing in `dotc` is used by both the comment cooking and the
11-
* dottydoc tool.
11+
* scaladoc tool.
1212
*
1313
* The comment cooking is used to expand comments with `@inheritdoc` and
1414
* `@define` annotations. The rest of the comment is untouched and later
15-
* handled by dottydoc.
15+
* handled by scaladoc.
1616
*/
1717
object CommentParsing {
1818
import Chars._

docs/docs/usage/scaladoc/blog.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,33 @@ title: Built-in blog
77
Scaladoc allows you to include a simple blog in your documentation. For now, it
88
provides only basic features. In the future, we plan to include more advanced
99
features like tagging or author pages.
10+
11+
Blog is treated a little differently than regular static sites. This article will help you set up your own blog.
12+
13+
## Proper directory setup
14+
15+
All your blogposts must be put under `blog/_posts` directory.
16+
17+
18+
```
19+
├── blog
20+
│ ├── _posts
21+
│ │ └── 2016-12-05-implicit-function-types.md
22+
│ └── index.html
23+
```
24+
25+
If you are using yaml [sidebar](./staticSite.html#sidebar) don't forget to place
26+
27+
```
28+
sidebar:
29+
- title: Blog
30+
```
31+
32+
somewhere inside the `yaml` tree representing the sidebar sections. Scaladoc will attach under that section all of your blogposts.
33+
34+
## Naming convention
35+
36+
All the blogpost filenames should start with date in numeric format matching `YYYY-MM-DD`.
37+
Example name is `2015-10-23-dotty-compiler-bootstraps.md`.
38+
39+

docs/docs/usage/scaladoc/docComments.md renamed to docs/docs/usage/scaladoc/linkingDocumentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: API Documentation
2+
title: Linking documentation
33
---
44

55
# {{ page.title }}
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
title: Scaladoc docstrings - specific Tags and Features
3+
---
4+
5+
# {{page.title}}
6+
7+
This chapter describes how to correctly write docstrings and how to use all the available features of scaladoc.
8+
Since many things are the same as in the old scaladoc, some parts are reused from this [article](https://docs.scala-lang.org/overviews/scaladoc/for-library-authors.html)
9+
10+
11+
Scaladoc extends Markdown with additional features, such as linking
12+
to API definitions. This can be used from within static documentation and blog
13+
posts to provide blend-in content.
14+
15+
16+
## Where to put docstrings
17+
18+
Scaladoc comments go before the items they pertain to in a special comment block that starts with a /** and ends with a */, like this:
19+
20+
```scala
21+
/** Start the comment here
22+
* and use the left star followed by a
23+
* white space on every line.
24+
*
25+
* Even on empty paragraph-break lines.
26+
*
27+
* Note that the * on each line is aligned
28+
* with the second * in /** so that the
29+
* left margin is on the same column on the
30+
* first line and on subsequent ones.
31+
*
32+
* Close the comment with *\/
33+
*
34+
* If you use Scaladoc tags (@param, @group, etc.),
35+
* remember to put them at separate lines with nothing preceding.
36+
*
37+
* For example:
38+
*
39+
* Calculate the square of the given number
40+
*
41+
* @param d the Double to square
42+
* @return the result of squaring d
43+
*/
44+
def square(d: Double): Double = d * d
45+
```
46+
47+
In the example above, this Scaladoc comment is associated with the method square since it is right before it in the source code.
48+
49+
Scaladoc comments can go before fields, methods, classes, traits, objects.
50+
For now, scaladoc doesn't support straightforward solution to document packages. There is a dedicated github
51+
[issue](https://github.com/lampepfl/dotty/issues/11284), where you can check the current status of the problem.
52+
53+
For class primary constructors which in Scala coincide with the definition of the class itself, a @constructor tag is used to target a comment to be put on the primary constructor documentation rather than the class overview.
54+
55+
## Tags
56+
57+
Scaladoc uses `@<tagname>` tags to provide specific detail fields in the comments. These include:
58+
59+
### Class specific tags
60+
61+
- `@constructor` placed in the class comment will describe the primary constructor.
62+
63+
### Method specific tags
64+
65+
- `@return` detail the return value from a method (one per method).
66+
67+
### Method, Constructor and/or Class tags
68+
69+
- `@throws` what exceptions (if any) the method or constructor may throw.
70+
- `@param` detail a value parameter for a method or constructor, provide one per parameter to the method/constructor.
71+
- `@tparam` detail a type parameter for a method, constructor or class. Provide one per type parameter.
72+
73+
### Usage tags
74+
75+
- `@see` reference other sources of information like external document links or related entities in the documentation.
76+
- `@note` add a note for pre or post conditions, or any other notable restrictions or expectations.
77+
- `@example` for providing example code or related example documentation.
78+
79+
80+
### Member grouping tags
81+
82+
These tags are well-suited to larger types or packages, with many members. They allow you to organize the Scaladoc page into distinct sections, with each one shown separately, in the order that you choose.
83+
84+
These tags are not enabled by default! You must pass the -groups flag to Scaladoc in order to turn them on. Typically the sbt for this will look something like:
85+
86+
```scala
87+
Compile / doc / scalacOptions ++= Seq(
88+
"-groups"
89+
)
90+
```
91+
Each section should have a single-word identifier that is used in all of these tags, shown as `group` below. By default, that identifier is shown as the title of that documentation section, but you can use @groupname to provide a longer title.
92+
93+
Typically, you should put @groupprio (and optionally @groupname and @groupdesc) in the Scaladoc for the package/trait/class/object itself, describing what all the groups are, and their order. Then put @group in the Scaladoc for each member, saying which group it is in.
94+
95+
Members that do not have a `@group` tag will be listed as “Ungrouped” in the resulting documentation.
96+
97+
- `@group <group>` - mark the entity as a member of the `<group>` group.
98+
- `@groupname <group> <name>` - provide an optional name for the group. `<name>` is displayed as the group header before the group description.
99+
- `@groupdesc <group> <description>` - add optional descriptive text to display under the group name. Supports multiline formatted text.
100+
- `@groupprio <group> <priority>` - control the order of the group on the page. Defaults to 0. Ungrouped elements have an implicit priority of 1000. Use a value between 0 and 999 to set a relative position to other groups. Low values will appear before high values.
101+
102+
### Other tags
103+
104+
- `@author` provide author information for the following entity
105+
- `@version` the version of the system or API that this entity is a part of.
106+
- `@since` like `@version` but defines the system or API that this entity was first defined in.
107+
- `@deprecated` marks the entity as deprecated, providing both the replacement implementation that should be used and the version/date at which this entity was deprecated.
108+
- `@syntax <name>` let you change the parser for docstring. The default syntax is markdown, however you can change it using this directive. Currently available syntaxes are `markdown` or `wiki`, e. g. `@syntax wiki`
109+
110+
### Macros
111+
112+
- `@define <name> <definition>` allows use of $name in other Scaladoc comments within the same source file which will be expanded to the contents of `<definition>`.
113+
114+
If a comment is not provided for an entity at the current inheritance level, but is supplied for the overridden entity at a higher level in the inheritance hierarchy, the comment from the super-class will be used.
115+
116+
Likewise if `@param`, `@tparam`, `@return` and other entity tags are omitted but available from a superclass, those comments will be used.
117+
118+
### Explicit
119+
120+
For explicit comment inheritance, use the @inheritdoc tag.
121+
122+
### Markup
123+
124+
Scaladoc provides two syntax parsers: `markdown` (default) or `wikidoc`.
125+
It is still possible to embed HTML tags in Scaladoc (like with Javadoc), but not necessary most of the time as markup may be used instead.
126+
127+
#### Markdown
128+
129+
Markdown uses [commonmark flavour](https://spec.commonmark.org/current/) with two custom extensions:
130+
- `wikidoc` links for referencing convenience
131+
- `wikidoc` codeblocks with curly braces syntax
132+
133+
134+
#### Wikidoc
135+
136+
Wikidoc is syntax used for scala2 scaladoc. It is supported because of many existing source code, however it is **not** recommended to use it in new projects.
137+
Wikisyntax can be toggled on with flag `-comment-syntax wiki` globally, or with `@syntax wiki` directive in docstring.
138+
139+
Some of the standard markup available:
140+
141+
```
142+
`monospace`
143+
''italic text''
144+
'''bold text'''
145+
__underline__
146+
^superscript^
147+
,,subscript,,
148+
[[entity link]], e.g. [[scala.collection.Seq]]
149+
[[https://external.link External Link]], e.g. [[https://scala-lang.org Scala Language Site]]
150+
```
151+
152+
For more info about wiki links look at this [chapter](#linking-to-api)
153+
154+
Other formatting notes
155+
156+
- Paragraphs are started with one (or more) blank lines. `*` in the margin for the comment is valid (and should be included) but the line should be blank otherwise.
157+
- Headings are defined with surrounding `=` characters, with more `=` denoting subheadings. E.g. `=Heading=`, `==Sub-Heading==`, etc.
158+
- List blocks are a sequence of list items with the same style and level, with no interruptions from other block styles. Unordered lists can be bulleted using `-`, numbered lists can be denoted using `1.`, `i.`, `I.`, or `a.` for the various numbering styles. In both cases, you must have extra space in front, and more space makes a sub-level.
159+
160+
The markup for list blocks looks like:
161+
162+
```
163+
/** Here is an unordered list:
164+
*
165+
* - First item
166+
* - Second item
167+
* - Sub-item to the second
168+
* - Another sub-item
169+
* - Third item
170+
*
171+
* Here is an ordered list:
172+
*
173+
* 1. First numbered item
174+
* 1. Second numbered item
175+
* i. Sub-item to the second
176+
* i. Another sub-item
177+
* 1. Third item
178+
*/
179+
```
180+
181+
### General Notes for Writing Scaladoc Comments
182+
183+
Concise is nice! Get to the point quickly, people have limited time to spend on your documentation, use it wisely.
184+
Omit unnecessary words. Prefer returns X rather than this method returns X, and does X,Y & Z rather than this method does X, Y and Z.
185+
DRY - don’t repeat yourself. Resist duplicating the method description in the @return tag and other forms of repetitive commenting.
186+
187+
More details on writing Scaladoc
188+
189+
Further information on the formatting and style recommendations can be found in Scala-lang scaladoc style guide.
190+
191+
## Linking to API
192+
193+
Scaladoc allows linking to API documentation with Wiki-style links. Linking to
194+
`scala.collection.immutable.List` is as simple as
195+
`[[scala.collection.immutable.List]]`. For more information on the exact syntax, see [doc comment documentation](./linkingDocumentation.html#definition-links).

0 commit comments

Comments
 (0)