Dokka for MkDocs 0.5.3 is out! This release conta...
# opensavvy
c
Dokka for MkDocs 0.5.3 is out! This release contains a bug fix for the Gradle
:clean
task and dependency updates. https://dokka-mkdocs.opensavvy.dev
o
I guess I need to use something like this (abbreviating it to DfMD) for testballoon docs, so hopefully I can act as a kind of canary here. Maybe you could consider adding some info to the project's docs which would answer my questions: • Why would I need DfMD? What am I trying to accomplish? • What would be my alternatives if DfMD did not exist?
And "alternatives" including: What kind of function loss would I encounter? What would be impossible or cumbersome to do? What implications would it have for maintenance and code correctness in examples?
c
Thanks, I'll add that
The TL;DR though is “it's just a new display format for Dokka”. It's useful to avoid having information spread between multiple sources (e.g. the Arrow website vs the Arrow API documentation, the Ktor website vs the Ktor API documentation, etc), but fundamentally it's just a different display
(and it's quite experimental still, it's very hard to get info on how to do things correctly with Dokka)
o
Cool, so I guess it's about visual consistency. Are you aware of solutions that would help with • correctness of examples (make them compile or even run tests on them), • provide example snippets visually, then let users expand the full code, • let examples run in a custom playground (configured to include the necessary dependencies)?
c
Your points in order: • correctness of example: see Kotools Samples #kotools • example snippets visually: that's something I may be able to do • examples run in a configured playground: you need to self-host the Kotlin Playground for that, as it doesn't currently allow downloading dependencies. This is not currently supported by the MkDocs plugin but I could add it easily provided some configuration to give the hosted URL
o
Cool, I'll look at Kotools. Those visual snippets existed somewhere in the Kotlin docs on coroutines.
Kotools samples could also need some additional docs, stating that • it is JVM-only, • is purely text-based (i.e. does not use the compiler's code analysis, but regex instead), • makes very specific assumptions about what constitutes an example (basically, a limited version of kotlin-test functions, e.g. no backticks allowed), • always extracts the entire body. But I get the idea.
c
Sure, it's not my project, tell @Loïc Lamarque
l
Thanks @CLOVIS for the ping and @Oliver.O for the interest in Kotools Samples. I will try to cover your points regarding the Kotools Samples Gradle plugin: • It is JVM-only, which is stated in the README documentation of the GitHub project. Also, Kotlin Multiplatform support is planned for future releases (see issue #12). • It is not text-based. All samples are executed alongside tests for ensuring their correctness at compile and run times. • It limits some usages of Kotlin Test, like backticks, and always extracts the entire body of the sample, but we are open to improve the plugin. Feel free to suggest your improvements here. Hope that makes sense. 🙂
o
Thanks for clarifying. Indeed, the JVM-only situation is mentioned in the README, so I stand corrected. What I was referring to as being "text based" is the use of regular expressions to identify language constructs that constitute a sample like here, instead of using the compiler and its parser. I could not find a description about these expectations, so I wonder, for example, if a suspend function hosting sample code is possible.
l
That's true @Oliver.O, Kotools Samples mainly uses regular expressions for identifying language constructs. This means that, currently, a sample code can be a suspend function. For simplicity purpose (and lack of knowledge), I used regular expressions for solving the problem more easily than learning how the compiler works. So I would love to read your opinion about the pros and cons of using the compiler for parsing language constructs, and learning materials about that topic.
o
Using regular expressions is not necessarily a bad thing, but by necessity, it's not really Kotlin, it can deviate at any point. So it would be a good idea to thoroughly document the underlying assumptions ("what should the code containing a sample look like"). Otherwise, if I wanted to find out what's possible and what's not, I'd have to decipher complex regular expressions in source code, which is tedious. The main advantage of using a compiler plugin is that it can access code like the compiler sees it. So I can find a function body without worrying what the entire function declaration looks like. Using a compiler plugin to extract samples is pretty straightforward if you're familiar with compiler plugins. Otherwise, it may or may not be worth the effort of diving into that topic (the compiler API is vast). If you're curious, you could consult Brian Norman's • Writing Your Second Kotlin Compiler Plugin (blog series) and •

Writing Your Third Kotlin Compiler Plugin▾

(KotlinConf talk).
l
I understand your point about documenting assumptions @Oliver.O. It is worth noting that Kotools Samples supports samples written in Kotlin and Java (which is certainly why it uses regular expressions). The Gradle plugin already checks the content of sample sources before extracting it - if the source is invalid, it will indicate it with a specific message. Also, there is only 3 error cases for a sample source : multiple classes found, no public class found, and single-expression Kotlin function. Other than these, everything's fine. Thank you for your thoughts on using a compiler plugin and the resources.