Skip to content

Commit 3758801

Browse files
committed
Technical documentation
1 parent 171b575 commit 3758801

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

scaladoc/documentation/docs/design.md

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,120 @@
11
# Design of scaladoc
22

3+
Scaladoc is divided into 3 modules, that are:
4+
- scaladoc
5+
- scaladoc-js
6+
- scaladoc-testcases
37

8+
##### scaladoc
49

5-
## Interface
10+
This module consist core sourcecode and assets (css, js) used for building Scaladoc.
611

7-
scaladoc is intednted to be use with sbt as well as from commend line or from other buildtools. The main entry point to processing is [Main](dotty.tools.scaladoc.Main$) class with [[dotty.tools.scaladoc.Main$.main]].
12+
##### scaladoc-js
13+
14+
This module consist Scala sourcecode that is transpiled to JavaScript that is used by scaladoc for:
15+
- searchbar
16+
- social links
17+
- snippets processor
18+
19+
##### scaladoc-testcases
20+
21+
Project that is used for manual testing as well as for end-to-end tests of Scaladoc.
22+
23+
## scaladoc
24+
25+
### Interface
26+
27+
scaladoc is intended to be use with sbt as well as from command line or from any other buildtool. The main entry point
28+
- for sbt is [dotty.tools.dottydoc.Main](../../src/dotty/tools/dottydoc/Main.scala)
29+
This class is just for compatibility with old dottydoc and should be removed in the near future.
30+
- for CLI is [dotty.tools.scaladoc.Main](../../src/dotty/tools/scaladoc/Main.scala)
31+
32+
### The base pipeline
33+
34+
The base pipeline of processing the files is as follows:
35+
36+
1. Gathering code data from TASTY files.
37+
2. Creation of Members
38+
3. Apply transformers
39+
4. Rendering the members into HTML
40+
41+
Main processing starts from [Scaladoc](../../src/dotty/tools/scaladoc/Scaladoc.scala) class. This class is reponsible for checking
42+
input settings and setting up [DocContext](../../src/dotty/tools/scaladoc/DocContext.scala) properly, which is wrapping `CompilerContext` with
43+
all additional information required by Scaladoc.
44+
45+
Then everything goes to [ScalaModuleProvider](../../src/dotty/tools/scaladoc/ScalaModuleProvider.scala) where [Members](../../src/dotty/tools/scaladoc/api.scala) are created and then
46+
transformations are applied.
47+
48+
Transformers are used to add additional data that could not be added at `Member`'s tree creation time.
49+
50+
Example transformers used are: [ImplicitMembersExtensionTransformer](../../src/dotty/tools/scaladoc/transformers/ImplicitMembersExtensionTransformer.scala),
51+
[InheritanceInformationTransformer](../../src/dotty/tools/scaladoc/transformers/InheritanceInformationTransformer.scala),
52+
[SealedMarksGraphTransformer](../../src/dotty/tools/scaladoc/transformers/SealedMarksGraphTransformer.scala).
53+
54+
The last step is serialization members into HTML pages. Everything that lies under package [dotty.tools.scaladoc.renderers](../../src/dotty/tools/scaladoc/renderers). It's worth noticing that whole template of page is coded as HTML building DSL like scalatags. The DocStrings are rendered by:
55+
- if they are Markdown syntax comments - by flexmark dependency
56+
- if they are WikiDoc syntax comments - by our own implementation
57+
58+
Unmentioned packages are:
59+
#### [dotty.tools.scaladoc.parsers](../../src/dotty/tools/scaladoc/parsers)
60+
61+
Contains legacy parser for WikiDoc syntax CodeBlocks `{{{ }}}`.
62+
63+
#### [dotty.tools.scaladoc.site](../../src/dotty/tools/scaladoc/site)
64+
65+
Package responsible for generation static pages for blog and documentation.
66+
67+
#### [dotty.tools.scaladoc.tasty](../../src/dotty/tools/scaladoc/tasty)
68+
69+
Package havily used during `Members` creation. Contains preprocessors and parsers to extract `DocString` comments and
70+
all semantic data from TASTY files.
71+
72+
Worth mentioning are:
73+
- [TypesSupport](../../src/dotty/tools/scaladoc/tasty/TypesSupport.scala) - used to gather types that are human readable out of `Quotes` AST
74+
- [ClassLikeSupport](../../src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala) - used to gather Members information out of `Quotes` AST
75+
76+
#### [dotty.tools.scaladoc.translators](../../src/dotty/tools/scaladoc/translators)
77+
78+
Utilities to create signatures for given Member.
79+
80+
#### [dotty.tools.scaladoc.util](../../src/dotty/tools/scaladoc/util)
81+
82+
Utilities for html, IO and JSONs.
83+
84+
### Important model classes
85+
86+
The core model class is called [Member](../../src/dotty/tools/scaladoc/api.scala) which aggregates all semantic data about some element of code.
87+
It can represent Package, Class, Method etc. Members create Tree-like structure just like Classes do. Every `Member` has it's own identifier called
88+
[DRI](../../src/dotty/tools/scaladoc/DRI.scala). `DRI` is easily serializable and unique. It's name is related to `DRI` model class from dokka,
89+
on which scaladoc was firstly based. `DRI` lets you get URL of resource easily, doesn't matter if this is symbol from the same project or any external
90+
dependency (given that correct external dependency is configured).
91+
92+
### Testing
93+
94+
In project we have some unit tests and end-to-end tests.
95+
Unit tests are nothing special, just put them under `test` directory.
96+
If you would like to creat some end-to-end tests you should visit [ScaladocTest](../../test/dotty/tools/scaladoc/ScaladocTest.scala) or
97+
[BaseSignatureTest](../../test/dotty/tools/scaladoc/signatures/SignatureTest.scala).
98+
The former is useful for any end-to-end tests, especially when used with JSoup html parsing.
99+
The latter is used to compare expected/actual signatures of classes/methods etc.
100+
101+
To run tests just run `sbt scaladoc/test`
102+
103+
### Hack methods
104+
105+
Across the project there are multiple `hackXXX` methods around. The reasons why method is called like that can be various, however they probably do
106+
some nasty casting, try-catching or any other procedure that was becuase of TASTY/dotty shortcomings or minor bugs. In the near future we should
107+
revisit each of them and fix them on `dotty side or fix in any other way.
108+
109+
## scaladoc-js
110+
111+
### Interface
112+
113+
scaladoc-js is appended to js resources of published scaladoc. The main entry point is [Main](../../../scaladoc-js/src/Main.scala)
114+
As a main method just append your javascripts transfomers that you find sufficient.
115+
For now scaladoc-js handles Social Links and Searchbar, though there are plans to rewrite more js scipts like Diagram handler to Scala.js
116+
117+
## scaladoc-testcases
118+
119+
There is no general rule how to treat this package. If you want to use it as `easy to look up scaladoc output` module, just add your scala definitions
120+
somewhere under `src` directory and run `sbt scaladoc/generateTestcasesDocumentation`. If you would like to use it as end-to-end test sourcecode input, check out [Testing](#testing) chapter.

0 commit comments

Comments
 (0)