Nishant Aanjaney Jalan
06/02/2024, 1:44 PM@sample
tag described here is not fully descriptive of how to include a sample function. Can someone give me an example? Do you think it's good have an issue to improve the KDoc Docs?CLOVIS
06/02/2024, 1:49 PMsrc/test/kotlin
)
• you tell Dokka that the source set in which that function is declared is where samples are (it's somewhere in the Gradle config)
• then, you can use @sample <http://fully.qualified.name.to|fully.qualified.name.to>.Your.function
However, it's not a very useful feature at the moment, because in the HTML output it will generate a Kotlin Playground snippet, with a 'run' button, but since the Kotlin Playground doesn't let you import your own libraries, running it will always fail 😕CLOVIS
06/02/2024, 1:49 PMNishant Aanjaney Jalan
06/02/2024, 1:56 PMsamples
module inside my library repo that contains all example code and reference them in my library docs. So my tests are separate from src and also separate from samples. Do you think it's a good idea for KDoc? I am happy to put this issue on youtrack too.CLOVIS
06/02/2024, 1:59 PMsrc/
main/…
test/…
samples/…
I don't know the config for that from memory, but you need to create a new Configuration
to hold the dependencies, ensure it has a dependency on main
, then create a SourcetSet
from that Configuration
CLOVIS
06/02/2024, 2:00 PMNishant Aanjaney Jalan
06/02/2024, 2:01 PMBut you'd still have the problem that the generated Playground snippets won't runThat's okay for now, I can put a disclaimer in my documentation. Atleast that would be formatted nice with good syntax highlighting at the very least.
CLOVIS
06/02/2024, 2:03 PMkotlin
, you will get syntax highlighting as well (example). However, since it's just text and not actual code, it's easy to miss it being out of date 😕Adam S
06/02/2024, 3:31 PMCLOVIS
06/02/2024, 3:33 PMAdam S
06/02/2024, 3:47 PMAdam S
06/02/2024, 3:47 PMCLOVIS
06/02/2024, 3:57 PMMichael Krussel
06/03/2024, 12:19 PMLoïc Lamarque
06/09/2024, 1:24 PMmain
source. This link will allow the Gradle plugin to generate the according HTML documentation using Dokka.
If you are interested in this Gradle plugin, please react to this message so I can put some effort in making this project publicly available as soon as possible for the community.
Also, any name idea is welcomed. 😁CLOVIS
06/09/2024, 5:48 PMLoïc Lamarque
06/11/2024, 6:41 PMkdoc-test
fits for that project. This naming seems like the main focus is testing the documentation, which is not. The goal is to provide a mechanism for integrating readonly and testable samples in KDoc.
What do you think about kdoc-samples
?CLOVIS
06/12/2024, 7:27 AMLoïc Lamarque
06/12/2024, 8:23 PMCLOVIS
06/13/2024, 8:04 AMsrc/
main/…
test/…
sample/…
structure so samples are clearly separate, have clear dependencies, etc.
However, the part with having a way to hide parts of the code from the samples is very important. The #
syntax would probably require a lot of work to get working, but I'd be happy with something like
@Test
fun `sample for filter`() {
// region hide
val list = listOf(1, 2, 3, 4)
// endregion
list.filter { it % 2 == 0 }
}
When using this sample, only the last line would be part of the actual documentationCLOVIS
06/16/2024, 7:11 PMLoïc Lamarque
06/18/2024, 5:33 PMcheck
function should be shown in the documentation? I would love to remove that boilerplate, so I'm kind of interested by your suggestions. 👀CLOVIS
06/18/2024, 6:40 PMCLOVIS
06/18/2024, 6:41 PMMichael Krussel
06/18/2024, 6:42 PMLoïc Lamarque
06/18/2024, 7:00 PMLoïc Lamarque
06/18/2024, 7:01 PMCLOVIS
06/18/2024, 7:05 PM• Test that the behavior of the documented declaration is correct (though unit test).I think this is debatable. Some people will want tests to be part of the documentation, some won't. Since your version puts sample code directly in a proper source set, I wouldn't mind either way
CLOVIS
06/18/2024, 7:07 PMcheck
/`assert` etc. Maybe that would be worth asking people about it in #feed?Loïc Lamarque
06/18/2024, 7:19 PMcheck
or assert*
functions, but it seems to be a good idea for reducing boilerplate by executing the sample as a test. If seeing assertions in the documentation is disturbing, it could be possible to hide them using region tokens, like you've suggested earlier in this thread.CLOVIS
06/18/2024, 7:34 PMcheck(foo.bar == "my output")
to
println(foo.bar) // "my output"
automatically when generating the documentation 🤔Loïc Lamarque
06/18/2024, 7:50 PMCLOVIS
06/18/2024, 8:07 PMCLOVIS
06/18/2024, 8:08 PMassert_eq
in documentation examples, so I don't think it's particularly harder to readCLOVIS
06/18/2024, 8:08 PMCLOVIS
06/18/2024, 8:09 PMcheck
, nothing's stopping them"
Personally, I probably won't put assertions in my documentation (I just want to ensure it compiles, I have proper tests to ensure behavior).Loïc Lamarque
06/18/2024, 8:11 PMTo be honest, having examples in the documentation at all is not that much common in the Kotlin ecosystem, so…@CLOVIS Meaning that having read-only samples in the documentation would already be a massive improvement. 😉
CLOVIS
06/18/2024, 8:12 PMMichael Krussel
06/18/2024, 8:13 PMLoïc Lamarque
06/18/2024, 8:18 PMI have a very large library coming that I can't announce yet, I'm committing to at least one example for each function, and let me tell you, I'm worried of the next refactor. I'm not checking them manually to see if I forgot something.I have to grind on that thing for you then @CLOVIS. 👀
Kotiln itself has a lot of executable samples, but they are in their documentation and not API reference.Yes @Michael Krussel, but doing the same with another library than the Kotlin standard one very hard to do: the playground doesn't seem to include custom JARs in the compilation. That's currently the pain point.
CLOVIS
06/19/2024, 9:14 AMCLOVIS
06/19/2024, 9:15 AMLoïc Lamarque
06/19/2024, 7:09 PMCLOVIS
06/19/2024, 7:21 PMLoïc Lamarque
06/19/2024, 7:32 PMNishant Aanjaney Jalan
07/02/2024, 11:19 PMNishant Aanjaney Jalan
07/02/2024, 11:20 PMNishant Aanjaney Jalan
07/02/2024, 11:21 PMLoïc Lamarque
07/05/2024, 4:53 PMLoïc Lamarque
11/25/2024, 2:31 PM