This doc page is specific to Scala 3, and may cover new concepts not available in Scala 2. Unless otherwise stated, all the code examples in this page assume you are using Scala 3.
Scaladocâs main feature is creating API documentation from code comments.
By default, the code comments are understood as Markdown, though we also support Scaladocâs old Wiki syntax.
Syntax Definition linksOur definition link syntax is quite close to Scaladocâs syntax, though we have made some quality-of-life improvements.
Basic syntaxA definition link looks as follows: [[scala.collection.immutable.List]]
.
Which is to say, a definition link is a sequence of identifiers separated by .
. The identifiers can be separated with #
as well for Scaladoc compatibility.
By default, an identifier id
references the first (in source order) entity named id
. An identifier can end with $
, which forces it to refer to a value (an object, a value, a given); an identifier can also end with !
, which forces it to refer to a type (a class, a type alias, a type member).
The links are resolved relative to the current location in source. That is, when documenting a class, the links are relative to the entity enclosing the class (a package, a class, an object); the same applies to documenting definitions.
Special characters in links can be backslash-escaped, which makes them part of identifiers instead. For example, [[scala.collection.immutable\.List]]
references the class named `immutable.List`
in package scala.collection
.
We have extended Scaladoc definition links to make them a bit more pleasant to write and read in source. The aim was also to bring the link and Scala syntax closer together. The new features are:
package
can be used as a prefix to reference the enclosing package Example:
package utils
class C {
def foo = "foo".
}
/** See also [[package.C]]. */
class D {
def bar = "bar".
}
The package
keyword helps make links to the enclosing package shorter and a bit more resistant to name refactorings.
this
can be used as a prefix to reference the enclosing classlike Example:
class C {
def foo = "foo"
/** This is not [[this.foo]], this is bar. */
def bar = "bar"
}
Using a Scala keyword here helps make the links more familiar, as well as helps the links survive class name changes.
def `([.abusive.])` = ???
/** TODO: Figure out what [[`([.abusive.])`]] is. */
def foo = `([.abusive.])`
Previously (versions 2.x), Scaladoc required backslash-escaping to reference such identifiers. Now (3.x versions), Scaladoc allows using the familiar Scala backtick quotation.
There are a few reasons why weâve kept the Wiki syntax for documentation links instead of reusing the Markdown syntax. Those are:
[](definition)
vs [[definition]]
By far, most links in documentation are nameless. It should be obvious how to write them.[](#field)
vs [[#field]]
[](meth(Int))
vs [[meth(Int)]]
[](meth(Int, Float))
vs [[meth(Int, Float)]]
None of these make it completely impossible to use the standard Markdown link syntax, but they make it much more awkward and ugly than it needs to be. On top of that, Markdown link syntax doesnât even save any characters.
Contributors to this page:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4