Skip to content

Commit dd2c092

Browse files
abgruszeckiromanowski
authored andcommitted
Add docoumentation to new link syntax
1 parent 1815dcf commit dd2c092

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

docs/docs/usage/scala3doc/docComments.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,67 @@ title: API Documentation
44

55
# {{ page.title }}
66

7-
Scala3doc main feature is to create API documentation based on [doc comments](https://docs.scala-lang.org/style/scaladoc.html) known from scaladoc as well well as new syntax introduced in Scala 3.
7+
Scala3doc main feature is to create API documentation based on [doc comments](https://docs.scala-lang.org/style/scaladoc.html) known from scaladoc as well well as new syntax introduced in Scala 3.
8+
9+
## New syntax
10+
11+
### Links
12+
13+
The goal with the link syntax was to be as Scaladoc-compatible as possible,
14+
while also making the links a bit more pleasant to type and read.
15+
For the time being, Scala3doc mostly keeps Scaladoc's definition link syntax. We
16+
did, however, implement some improvements to it:
17+
18+
1. `package` can be used as a prefix to reference the enclosing package
19+
Example:
20+
```
21+
package utils
22+
class C {
23+
def foo = "foo".
24+
}
25+
/** See also [[package.C]]. */
26+
class D {
27+
def bar = "bar".
28+
}
29+
```
30+
Links to the enclosing package in Scaladoc required mentioning the complete
31+
package name. Using the `package` keyword (similarly to how one would use
32+
`this` in expressions) helps make such links shorter.
33+
1. `this` can be used as a prefix to reference the enclosing classlike
34+
Example:
35+
```
36+
class C {
37+
def foo = "foo"
38+
/** This is not [[this.foo]], this is bar. */
39+
def bar = "bar"
40+
}
41+
```
42+
Using a Scala keyword here helps make the links more familiar, as well as
43+
helps the links survive class name changes.
44+
1. Backticks can be used to escape identifiers
45+
Example:
46+
```
47+
def `([.abusive.])` = ???
48+
/** TODO: Figure out what [[`([.abusive.])`]] is. */
49+
def foo = `([.abusive.])`
50+
```
51+
Scaladoc required backslash-escaping to reference such identifiers. Instead,
52+
Scala3doc allows using the familiar Scala backtick quotation.
53+
54+
### Why keep the Wiki syntax?
55+
56+
There are a few reasons why we've kept the Wiki syntax for documentation links
57+
instead of reusing the Markdown syntax. Those are:
58+
59+
1. Nameless links in Markdown are ugly: `[](definition)` vs `[[definition]]`
60+
By far, most links in documentation are nameless. It should be obvious how to
61+
write them.
62+
2. Local member lookup collides with URL fragments: `[](#field)` vs `[[#field]]`
63+
3. Overload resolution collides with MD syntax: `[](meth(Int))` vs `[[meth(Int)]]`
64+
4. Now that we have a parser for the link syntax, we can allow spaces inside (in
65+
Scaladoc one needed to slash-escape those), but that doesn't get recognized
66+
as a link in Markdown: `[](meth(Int, Float))` vs `[[meth(Int, Float)]]`
67+
68+
None of these make it completely impossible to use the standard Markdown link
69+
syntax, but they make it much more awkward and ugly than it needs to be. On top
70+
of that, Markdown link syntax doesn't even save any characters.

0 commit comments

Comments
 (0)