Skip to content

Commit 92d697e

Browse files
committed
Update Developer Guides (#3088)
(cherry picked from commit f7bd2ce)
1 parent fccbdab commit 92d697e

27 files changed

+646
-618
lines changed

.github/workflows/gh-pages-deploy-mkdocs.yml .github/workflows/gh-pages-deploy-dev-docs.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Deploy MkDocs to GitHub Pages
1+
name: Deploy developer docs to GitHub Pages
22

33
on:
44
push:
55
branches:
66
- master
77
paths:
8-
- 'mkdocs/**'
8+
- 'docs-developer/**'
99
release:
1010
types: [ published ]
1111

@@ -25,7 +25,7 @@ jobs:
2525
- uses: gradle/gradle-build-action@v2
2626
with:
2727
gradle-home-cache-cleanup: true
28-
- name: Get current dokka version
28+
- name: Get current Dokka version
2929
run: echo "DOKKA_VERSION=`./gradlew :properties | grep '^version:.*' | cut -d ' ' -f 2`" >> $GITHUB_ENV
3030
working-directory: ./dokka
3131
- name: Build docs
@@ -35,6 +35,6 @@ jobs:
3535
uses: peaceiris/actions-gh-pages@v3
3636
with:
3737
github_token: ${{ secrets.GITHUB_TOKEN }}
38-
publish_dir: ./dokka/mkdocs/build/mkdocs
38+
publish_dir: ./dokka/docs-developer/build/mkdocs
3939
keep_files: true
4040
full_commit_message: Publish ${{ env.DOKKA_VERSION }} documentation

docs-developer/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Developer documentation
2+
3+
This module contains developer documentation which is published to GitHub pages:
4+
[kotlin.github.io/dokka](https://kotlin.github.io/dokka/).
5+
6+
It is built using the [gradle-mkdocs-plugin](https://github.com/xvik/gradle-mkdocs-plugin).
7+
8+
## Building
9+
10+
You can build the documentation locally:
11+
12+
```Bash
13+
./gradlew :docs-developer:mkdocsBuild
14+
```
15+
16+
The output directory is `build/mkdocs`.
17+
18+
### Docker
19+
20+
Alternatively, you can use Docker:
21+
22+
```bash
23+
docker run --rm -it -p 8000:8000 -v ./docs-developer/src/doc:/docs squidfunk/mkdocs-material
24+
```
25+
26+
This will build the docs and start a web server under [localhost:8000/Kotlin/dokka](http://localhost:8000/Kotlin/dokka/).
27+
28+
### Livereload server
29+
30+
Alternatively, you can run a livereload server that automatically rebuilds documentation on every change:
31+
32+
```Bash
33+
./gradlew :docs-developer:mkdocsServe
34+
```
35+
36+
By default, it is run under [localhost:3001](http://localhost:3001/), but you can change it in
37+
[mkdocs.yml](src/doc/mkdocs.yml) by setting the `dev_addr` option.
38+
39+
## Publishing
40+
41+
The documentation is published automatically for all changes in master and for every GitHub release.
42+
43+
See [gh-pages.yml](../.github/workflows/gh-pages-deploy-dev-docs.yml) workflow configuration for more details.

mkdocs/build.gradle.kts docs-developer/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import org.jetbrains.dokkaVersionType
22
import org.jetbrains.DokkaVersionType
33

44
plugins {
5-
id("ru.vyarus.mkdocs") version "2.3.0"
5+
id("ru.vyarus.mkdocs") version "2.4.0"
66
}
77

88
if (dokkaVersionType != DokkaVersionType.RELEASE) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Architecture overview
2+
3+
Normally, you would think that a tool like Dokka simply parses some programming language sources and generates
4+
HTML pages for whatever it sees along the way, with little to no abstractions. That would be the simplest and
5+
the most straightforward way to implement an API documentation engine.
6+
7+
However, it was clear that Dokka may need to generate documentation from various sources (not only Kotlin), that users
8+
might request additional output formats (like Markdown), that users might need additional features like supporting
9+
custom KDoc tags or rendering [mermaid.js](https://mermaid.js.org/) diagrams - all these things would require changing
10+
a lot of code inside Dokka itself if all solutions were hardcoded.
11+
12+
For this reason, Dokka was built from the ground up to be easily extensible and customizable by adding several layers
13+
of abstractions to the data model, and by providing pluggable extension points, giving you the ability to introduce
14+
selective changes on a given level.
15+
16+
## Overview of data model
17+
18+
Generating API documentation begins with input source files (`.kt`, `.java`, etc) and ends with some output files
19+
(`.html`/`.md`, etc). However, to allow for extensibility and customization, several input and output independent
20+
abstractions have been added to the data model.
21+
22+
Below you can find the general pipeline of processing data gathered from sources and the explanation for each stage.
23+
24+
```mermaid
25+
flowchart TD
26+
Input --> Documentables --> Pages --> Output
27+
```
28+
29+
* `Input` - generalization of sources, by default Kotlin / Java sources, but could be virtually anything
30+
* [`Documentables`](data_model/documentable_model.md) - unified data model that represents _any_ parsed sources as a
31+
tree, independent of the source language. Examples of a `Documentable`: class, function, package, property, etc
32+
* [`Pages`](data_model/page_content.md) - universal model that represents output pages (e.g a function/property page)
33+
and the content it's composed of (lists, text, code blocks) that the users needs to see. Not to be confused with
34+
`.html` pages. Goes hand in hand with the so-called [Content model](data_model/page_content.md#content-model).
35+
* `Output` - specific output formats like HTML / Markdown / Javadoc and so on. This is a mapping of the pages/content
36+
model to a human-readable and visual representation. For instance:
37+
* `PageNode` is mapped as
38+
* `.html` file for the HTML format
39+
* `.md` file for the Markdown format
40+
* `ContentList` is mapped as
41+
* `<li>` / `<ul>` for the HTML format
42+
* `1.` / `*` for the Markdown format
43+
* `ContentCodeBlock` is mapped as
44+
* `<code>` or `<pre>` with some CSS styles in the HTML format
45+
* Text wrapped in triple backticks for the Markdown format
46+
47+
48+
You, as a Dokka developer or a plugin writer, can use extension points to introduce selective changes to the
49+
model on one particular level without altering everything else.
50+
51+
For instance, if you wanted to make an annotation / function / class invisible in the final documentation, you would only
52+
need to modify the `Documentables` level by filtering undesirable declarations out. If you wanted to display all overloaded
53+
methods on the same page instead of on separate ones, you would only need to modify the `Pages` layer by merging multiple
54+
pages into one, and so on.
55+
56+
For a deeper dive into Dokka's model with more examples and details,
57+
see sections about [Documentables](data_model/documentable_model.md) and [Page/Content](data_model/page_content.md)
58+
59+
For an overview of existing extension points that let you transform Dokka's models, see
60+
[Core extension points](extension_points/core_extension_points.md) and [Base extensions](extension_points/base_plugin.md).
61+
62+
## Overview of extension points
63+
64+
An _extension point_ usually represents a pluggable interface that performs an action during one of the stages of
65+
generating documentation. An _extension_ is, therefore, an implementation of the interface which is extending the
66+
extension point.
67+
68+
You can create extension points, provide your own implementations (extensions) and configure them. All of
69+
this is possible with Dokka's plugin / extension point API.
70+
71+
Here's a sneak peek of the DSL:
72+
73+
```kotlin
74+
// declare your own plugin
75+
class MyPlugin : DokkaPlugin() {
76+
// create an extension point for developers to use
77+
val signatureProvider by extensionPoint<SignatureProvider>()
78+
79+
// provide a default implementation
80+
val defaultSignatureProvider by extending {
81+
signatureProvider with KotlinSignatureProvider()
82+
}
83+
84+
// register our own extension in Dokka's Base plugin by overriding its default implementation
85+
val dokkaBasePlugin by lazy { plugin<DokkaBase>() }
86+
val multimoduleLocationProvider by extending {
87+
(dokkaBasePlugin.locationProviderFactory
88+
providing MultimoduleLocationProvider::Factory
89+
override dokkaBasePlugin.locationProvider)
90+
}
91+
}
92+
93+
class MyExtension(val context: DokkaContext) {
94+
95+
// use an existing extension
96+
val signatureProvider: SignatureProvider = context.plugin<MyPlugin>().querySingle { signatureProvider }
97+
98+
fun doSomething() {
99+
signatureProvider.signature(..)
100+
}
101+
}
102+
103+
interface SignatureProvider {
104+
fun signature(documentable: Documentable): List<ContentNode>
105+
}
106+
107+
class KotlinSignatureProvider : SignatureProvider {
108+
override fun signature(documentable: Documentable): List<ContentNode> = listOf()
109+
}
110+
```
111+
112+
For a deeper dive into extensions and extension points, see [Introduction to Extensions](extension_points/extension_points.md).
113+
114+
For an overview of existing extension points, see [Core extension points](extension_points/core_extension_points.md) and
115+
[Base extensions](extension_points/base_plugin.md).
116+
117+
## Historical context
118+
119+
This is a second iteration of Dokka that was built from scratch.
120+
121+
If you want to learn more about why Dokka was redesigned this way, watch this great talk by Paweł Marks:
122+
[New Dokka - Designed for Fearless Creativity](https://www.youtube.com/watch?v=OvFoTRhqaKg). The general principles
123+
and general architecture are the same, although it may be outdated in some areas, so please double-check.

mkdocs/src/doc/docs/developer_guide/architecture/data_model/documentables.md docs-developer/src/doc/docs/developer_guide/architecture/data_model/documentable_model.md

+42-36
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
# Documentables Model
1+
# Documentable Model
22

3-
Documentables represent data that is parsed from sources. Think of this data model as of something that could be
4-
seen or produced by a compiler frontend, it's not far off from the truth.
3+
The Documentable model represents the data that is parsed from some programming language sources. Think of this data as
4+
of something that could be seen or produced by a compiler frontend, it's not far off from the truth.
55

6-
By default, documentables are parsed from `Descriptor` (for `Kotlin`)
7-
and [Psi](https://plugins.jetbrains.com/docs/intellij/psi.html)
8-
(for `Java`) models. Code-wise, you can have a look at following classes:
6+
By default, the documentables are created from:
97

10-
* `DefaultDescriptorToDocumentableTranslator` - responsible for `Kotlin` -> `Documentable` mapping
11-
* `DefaultPsiToDocumentableTranslator` - responsible for `Java` -> `Documentable` mapping
8+
* Descriptors (Kotlin's K1 compiler)
9+
* Symbols (Kotlin's K2 compiler)
10+
* [PSI](https://plugins.jetbrains.com/docs/intellij/psi.html) (Java's model).
1211

13-
Upon creation, it's a collection of trees, each with `DModule` as root.
12+
Code-wise, you can have a look at following classes:
1413

15-
Take some arbitrary `Kotlin` source code that is located within the same module:
14+
* `DefaultDescriptorToDocumentableTranslator` - responsible for Kotlin -> `Documentable` mapping
15+
* `DefaultPsiToDocumentableTranslator` - responsible for Java -> `Documentable` mapping
16+
17+
Upon creation, the documentable model represents a collection of trees, each with `DModule` as root.
18+
19+
Take some arbitrary Kotlin source code that is located within the same module:
1620

1721
```kotlin
1822
// Package 1
@@ -28,7 +32,7 @@ enum class Enum { }
2832
val topLevelProperty: String
2933
```
3034

31-
This would be represented roughly as the following `Documentable` tree:
35+
This would be represented roughly as the following Documentable tree:
3236

3337
```mermaid
3438
flowchart TD
@@ -43,20 +47,23 @@ flowchart TD
4347
secondPackage --> secondPackageProperty[DProperty]
4448
```
4549

46-
At later stages of transformation, all trees are folded into one (by `DocumentableMerger`).
50+
At later stages of transformation, all trees are folded into one by
51+
[DocumentableMerger](../extension_points/core_extension_points.md#documentablemerger).
4752

4853
## Documentable
4954

50-
The main building block of documentables model is `Documentable` class. It's the base class for all more specific types
51-
that represent elements of parsed sources with mostly self-explanatory names (`DFunction`, `DPackage`, `DProperty`, etc)
52-
.
53-
`DClasslike` is the base class for class-like documentables such as `DClass`, `DEnum`, `DAnnotation`, etc.
55+
The main building block of the documentable model is the `Documentable` class. It is the base class for all more specific
56+
types. All implementations represent elements of source code with mostly self-explanatory names: `DFunction`,
57+
`DPackage`, `DProperty`, and so on.
58+
59+
`DClasslike` is the base class for all class-like documentables, such as `DClass`, `DEnum`, `DAnnotation` and others.
60+
61+
The contents of each documentable normally represent what you would see in the source code.
5462

55-
The contents of each documentable normally represent what you would see in source code. For instance, if you open
56-
`DClass`, you should find that it contains references to functions, properties, companion object, constructors and so
57-
on.
58-
`DEnum` should have references to enum entries, and `DPackage` can have references to both classlikes and top-level
59-
functions and properties (`Kotlin`-specific).
63+
For example, if you open
64+
`DClass`, you should find that it contains references to functions, properties, companion objects, constructors and so
65+
on. `DEnum` should have references to its entries, and `DPackage` can have references to both classlikes and top-level
66+
functions and properties (Kotlin-specific).
6067

6168
Here's an example of a documentable:
6269

@@ -85,7 +92,7 @@ data class DClass(
8592

8693
___
8794

88-
There are three non-documentable classes that important for this model:
95+
There are three non-documentable classes that are important for this model:
8996

9097
* `DRI`
9198
* `SourceSetDependent`
@@ -94,9 +101,9 @@ There are three non-documentable classes that important for this model:
94101
### DRI
95102

96103
`DRI` stans for _Dokka Resource Identifier_ - a unique value that identifies a specific `Documentable`.
97-
All references and relations between documentables (other than direct ownership) are described using `DRI`.
104+
All references and relations between the documentables (other than direct ownership) are described using `DRI`.
98105

99-
For example, `DFunction` with a parameter of type `Foo` has only `Foo`'s `DRI`, not the actual reference
106+
For example, `DFunction` with a parameter of type `Foo` only has `Foo`'s `DRI`, but not the actual reference
100107
to `Foo`'s `Documentable` object.
101108

102109
#### Example
@@ -146,11 +153,11 @@ kotlinx.coroutines/MainCoroutineDispatcher/limitedParallelism/#kotlin.Int/Pointi
146153
### SourceSetDependent
147154

148155
`SourceSetDependent` helps handling multiplatform data by associating platform-specific data (declared with either
149-
`expect` or `actual` modifier) with particular
156+
`expect` or `actual` modifiers) with particular
150157
[source sets](https://kotlinlang.org/docs/multiplatform-discover-project.html#source-sets).
151158

152-
This comes in handy if `expect`/`actual` declarations differ. For instance, the default value for `actual` might differ
153-
from that declared in `expect`, or code comments written for `expect` might be different from what's written
159+
This comes in handy if the `expect` / `actual` declarations differ. For example, the default value for `actual` might
160+
differ from that declared in `expect`, or code comments written for `expect` might be different from what's written
154161
for `actual`.
155162

156163
Under the hood, it's a `typealias` to a `Map`:
@@ -171,18 +178,18 @@ ___
171178

172179
## Documentation model
173180

174-
Documentation model is used alongside Documentables to store data obtained by parsing
175-
code comments (such as `KDoc`/`Javadoc`).
181+
The Documentation model is used alongside documentables to store data obtained by parsing
182+
code comments (such as KDocs / Javadocs).
176183

177184
### DocTag
178185

179186
`DocTag` describes a specific documentation syntax element.
180187

181-
It's universal across source languages. For instance, DocTag `B` is the same for `**bold**` in `Kotlin` and
182-
`<b>bold</b>` in `Java`.
188+
It's universal across language sources. For example, the DocTag `B` is the same for `**bold**` in Kotlin and
189+
`<b>bold</b>` in Java.
183190

184-
However, some `DocTag` elements are specific to a certain language, there are many such examples for `Java`
185-
because it allows HTML tags inside `Javadoc` comments, some of which are simply not possible to reproduce with `Markdown`.
191+
However, some DocTag elements are specific to one language. There are many such examples for Java, because it allows
192+
HTML tags inside the Javadoc comments, some of which are simply not possible to reproduce with Markdown that KDocs use.
186193

187194
`DocTag` elements can be deeply nested with other `DocTag` children elements.
188195

@@ -218,10 +225,9 @@ data class CodeBlock(
218225

219226
### TagWrapper
220227

221-
`TagWrapper` describes the whole comment description or a specific comment tag.
222-
For example: `@see` / `@author` / `@return`.
228+
`TagWrapper` describes the whole comment description or a specific comment tag. For example: `@see` / `@author` / `@return`.
223229

224-
Since each such section may contain formatted text inside of it, each `TagWrapper` has `DocTag` children.
230+
Since each such section may contain formatted text inside it, each `TagWrapper` has `DocTag` children.
225231

226232
```kotlin
227233
/**

0 commit comments

Comments
 (0)