-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dokka K2 analysis #3094
Dokka K2 analysis #3094
Conversation
05a213e
to
ab5f311
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only reviewed the Analysis API usage; I did not look at logic or Dokka-specific code
...s/plugin/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/ResolveKDocLink.kt
Outdated
Show resolved
Hide resolved
...tlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/SymbolAccessorConventionUtil.kt
Outdated
Show resolved
Hide resolved
...tlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/SymbolAccessorConventionUtil.kt
Outdated
Show resolved
Hide resolved
...jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt
Outdated
Show resolved
Hide resolved
...jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt
Outdated
Show resolved
Hide resolved
...dokka/analysis/kotlin/symbols/kdoc/moduledocs/ModuleAndPackageDocumentationParsingContext.kt
Outdated
Show resolved
Hide resolved
* Map [KtAnnotationApplication] to Dokka [Annotations.Annotation] | ||
*/ | ||
internal class AnnotationTranslator { | ||
private fun KtAnalysisSession.getFileLevelAnnotationsFrom(symbol: KtSymbol) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KtAnalysisSession
is supposed to be used as a context receiver, this way you can always use your extension receiver :
context(KtAnalysisSession)
private fun KtSymbol.getFileLevelAnnotationsFrom() = ...
.../main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/AnnotationTranslator.kt
Outdated
Show resolved
Hide resolved
b1c4420
to
957bc34
Compare
…chyBuilder, java accessors
957bc34
to
a646328
Compare
ff9cb29
to
9b79b24
Compare
runtimeOnly(project(path = ":subprojects:analysis-kotlin-descriptors", configuration = "shadow")) | ||
//runtimeOnly(project(path = ":subprojects:analysis-kotlin-symbols", configuration = "shadow")) | ||
//runtimeOnly(project(path = ":subprojects:analysis-kotlin-descriptors", configuration = "shadow")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe removing this line will break 3rd party plugins, even for K1, as their tests will have no analysis implementation. It's worth checking or reverting it to play it safe.
val expectedMessage = "Wrong AST Tree. Header does not contain expected content in Test.kt/example.Test, element starts from offset 0 and ends 3: ###" | ||
assert( | ||
exception?.message == expectedMessage | ||
|| /* for K2 */ exception?.cause?.cause?.message == expectedMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this exception throw from the markdown module? Why is the depth different with K2? Maybe we need to re-wrap it somewhere to remove excessive layers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugins/base/src/test/kotlin/superFields/DescriptorSuperPropertiesTest.kt
Outdated
Show resolved
Hide resolved
plugins/base/src/test/kotlin/filter/KotlinArrayDocumentableReplacerTest.kt
Outdated
Show resolved
Hide resolved
...-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/DefaultPsiToDocumentableTranslator.kt
Outdated
Show resolved
Hide resolved
|
||
|
||
|
||
// ----------- copy-paste from IDE ---------------------------------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions:
- Is this the only copy-pasted code from IDE?
- Is this the only copy-pasted code in general, from anywhere? Maybe something was copy-pasted from the compiler or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Yes
- No, there is some code in KotlinAnalysis, but it is related to the Standalone prototype.
7ec03e6
to
565be8f
Compare
565be8f
to
9e65b29
Compare
2b012de
to
8da7ce2
Compare
c169487
to
83d6ad4
Compare
7c888ad
to
de2426c
Compare
Compiler: Kotlin 1.9.0
The PR stems from #2995, but it's using a recent refactoring #3034.
The PR description is WIP.
Dokka has its own documentable model to represent analyzed code, The analysis is performed by a compiler frontend.
In K1 the compiler frontend has descriptors that use the underlying Binding Context (global shared stateful structure). Dokka just maps descriptors to Documentable by
DefaultDescriptorToDocumentableTranslator
.K2 compiler has FIR tree, which means “Frontend Intermediate Representation”, instead of Binding Context. But we do not use FIR in Dokka directly, since it is too low-level for analysis. The Kotlin compiler provides high-level Analysis API for this case. The API is used by KSP too. Analysis API represent elements of FIR (declarations, parameters and so on) as Symbols. For more details see KtSymbolByFirBuilder, KtSymbol.
For Dokka symbol is the replacement of descriptors in K2.
The general data pipeline is:
In code:
Also, to set up the environment of project analysis in K1 we use idea dependencies (or copy-past from there). In K2 for these aims there is Standalone Analysis API from Analysis API.
Overview
Main principles
KtAnalysisSession
. Symbols are bounded byKtAnalysisSession
(althoughKtAlwaysAccessibleLifetimeToken
does not check their lifetime; a session caches them, and a session is cached byKtAnalysisSessionProvider
). The documentable model keeps almost full information from symbols. Also, there are analysis principles, but Dokka does not haveReadAction
unlike IDE.Entry point
The main entry point is
DefaultSymbolToDocumentableTranslator
(this is an extension for the extension point ), that used by the Dokka core to build Documentable model by source set.Across running Dokka we keep
StandaloneAnalysisAPISession
andKtSourceModule
instances intoAnalysisContex
per source set. (SeecreateAnalysisContext
).AnalysisContex
is used in 'DefaultSymbolToDocumentableTranslator' and other services, that need additional analysis. (see classes inservices
package)Differences from K1 in documentable model
AdditionalModifiers
,Annotations
).KotlinModifier.Empty
is used only for constructorsTranslatorError
that contains a file path where it has happened. In this case, It fails to generate documentation. (Or should Dokka skip a declaration with exception and only emit a warning in the logger?)Current state
Testing
Currently, K2 translator is tested on unit tests of base plugin. To run it, you can use
symbolsTest
task.Some tests (currently, 37 from 843) in K2 analysis are muted by a special annotation (
@OnlyDescriptors
or@OnlyDescriptorsMPP
):open
.Plans
kotlin-as-java
andjavadoc
plugins in K2