-
Notifications
You must be signed in to change notification settings - Fork 470
Extract Kotlin Playground runnable samples into a separate plugin #4329
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
base: master
Are you sure you want to change the base?
Extract Kotlin Playground runnable samples into a separate plugin #4329
Conversation
…lesConfigurationTest
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.
Pull Request Overview
This PR introduces a new Dokka plugin called plugin-runnable-samples that makes @sample code blocks interactive and runnable using Kotlin Playground. The plugin extracts runnable samples functionality from the base plugin into a standalone, optional plugin.
Key changes:
- Creates new
plugin-runnable-samplesmodule with transformer, installer, and configuration components - Removes Kotlin Playground integration from the base plugin (DefaultSamplesTransformer, styles, scripts)
- Updates base plugin to use callback pattern for dark mode changes instead of directly managing Kotlin Playground
- Updates integration test expectations to reflect removed Kotlin Playground script references
Reviewed Changes
Copilot reviewed 156 out of 207 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| settings.gradle.kts | Adds new plugin-runnable-samples module to build |
| plugin-runnable-samples/* | New plugin with transformer, installer, configuration, tests, and resources |
| plugin-base/* | Removes runnable samples logic, styles, and scripts; refactors dark mode handling |
| dokka-subprojects/README.md | Documents new plugin in project structure |
| integration test files | Updates expected output to remove Kotlin Playground references |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private fun createSampleBody(imports: List<String>, body: String) = | ||
| // takeIf {} is needed so that joinToString's postfix is not added for empty lists, | ||
| // and trimMargin() then removes the first empty line | ||
| """ |${ |
Copilot
AI
Nov 3, 2025
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.
The comment on lines 101-102 is misaligned with the code. The opening triple-quote for the multi-line string starts on line 103, but the comment explaining trimMargin() appears on line 102, creating confusion about what the comment applies to. The comment should be moved above line 100 or reformatted to clearly explain the entire function's behavior.
|
(sorry, closed by accident)
|
…ndServer to KotlinPlaygroundServer
vmishenev
left a comment
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.
Great 👍
I have some minor comments, but overall LGTM.
I would also add a unit test to check whether KotlinPlaygroundSamplesTransformer is applied.
.../main/kotlin/org.jetbrains.dokka.kotlinplaygroundsamples/KotlinPlaygroundSamplesInstaller.kt
Outdated
Show resolved
Hide resolved
dokka-subprojects/plugin-kotlin-playground-samples/api/plugin-kotlin-playground-samples.api
Outdated
Show resolved
Hide resolved
...projects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/renderers/html/HtmlRenderer.kt
Show resolved
Hide resolved
| } | ||
| }.transformContentPagesTree { | ||
| it.modified( | ||
| embeddedResources = it.embeddedResources + scriptsPages |
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.
This will add the JS script to every page.
I think it is a bit better to add the script only on pages containing samples, in the same way it is done for playground.min.js.
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.
fixed, see 86af502
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.
This is not in the same way as it is done for playground.min.js.
Is it possible to add script and style resources to a page in KotlinPlaygroundSamplesTransformer? See KotlinPlaygroundSamplesTransformer.kt:52
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.
done, see d299198
|
|
||
| public class KotlinPlaygroundSamplesStylesInstaller(private val dokkaContext: DokkaContext) : PageTransformer { | ||
| private val stylesPages = listOf( | ||
| "styles/kotlin-playground-samples.css" |
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.
The same as the one above regarding the script.
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.
idk where it can be reused in styles, in scripts i have refactored
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.
You have already changed it for the stylesheets in 86af502
...n/kotlin/org.jetbrains.dokka.kotlinplaygroundsamples/KotlinPlaygroundSamplesConfiguration.kt
Outdated
Show resolved
Hide resolved
|
@whyoleg Would you like to review this PR? Or will merging without your review be okay? |
Yeah, I would like to take a look! I will do it today/tomorrow. |
whyoleg
left a comment
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.
Nice!
We should probably create an issue to enable samples for kotlinx and stdlib?
@berezinant, could you please review the changes to .js/.css files (this and in plugin-kotlin-playground-samples module)?
Additionally, @berezinant, playground samples are now disabled by default. Should we still enable them in ui-showcase?
...src/main/kotlin/org/jetbrains/dokka/kotlinPlaygroundSamples/KotlinPlaygroundSamplesPlugin.kt
Outdated
Show resolved
Hide resolved
...src/main/kotlin/org.jetbrains.dokka.kotlinplaygroundsamples/KotlinPlaygroundSamplesPlugin.kt
Outdated
Show resolved
Hide resolved
…s registration to extension points
8ed1cd6 to
24fc432
Compare
dokka-subprojects/plugin-kotlin-playground-samples/build.gradle.kts
Outdated
Show resolved
Hide resolved
…KotlinPlaygroundSamplesTransformer to internal




Impl #3041