Skip to content
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

Fix invisible packages for module names with space #3019

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ open class HtmlRenderer(
node.isAnchorable -> buildAnchor(
node.anchor!!,
node.anchorLabel!!,
node.sourceSetsFilters
node.buildSourceSetFilterValues()
) { childrenCallback() }
node.extra[InsertTemplateExtra] != null -> node.extra[InsertTemplateExtra]?.let { templateCommand(it.command) }
?: Unit
Expand Down Expand Up @@ -568,10 +568,15 @@ open class HtmlRenderer(
private fun FlowContent.addSourceSetFilteringAttributes(
contextNode: ContentGroup,
) {
attributes["data-filterable-current"] = contextNode.sourceSets.joinToString(" ") {
it.sourceSetIDs.merged.toString()
}
attributes["data-filterable-set"] = contextNode.sourceSets.joinToString(" ") {
attributes["data-filterable-current"] = contextNode.buildSourceSetFilterValues()
attributes["data-filterable-set"] = contextNode.buildSourceSetFilterValues()
}

private fun ContentNode.buildSourceSetFilterValues(): String {
// This value is used in HTML and JS for filtering out source set declarations,
// it is expected that the separator is the same here and there.
// See https://github.com/Kotlin/dokka/issues/3011#issuecomment-1568620493
return this.sourceSets.joinToString(",") {
it.sourceSetIDs.merged.toString()
}
}
Expand Down Expand Up @@ -699,7 +704,7 @@ open class HtmlRenderer(
buildAnchor(anchor, anchorLabel, sourceSets) {}

private fun FlowContent.buildAnchor(node: ContentNode) {
node.anchorLabel?.let { label -> buildAnchor(node.anchor!!, label, node.sourceSetsFilters) }
node.anchorLabel?.let { label -> buildAnchor(node.anchor!!, label, node.buildSourceSetFilterValues()) }
}


Expand Down Expand Up @@ -982,8 +987,5 @@ private val PageNode.isNavigable: Boolean
private fun PropertyContainer<ContentNode>.extraHtmlAttributes() = allOfType<SimpleAttr>()
private fun PropertyContainer<ContentNode>.extraTabbedContentType() = this[TabbedContentTypeExtra]

private val ContentNode.sourceSetsFilters: String
get() = sourceSets.sourceSetIDs.joinToString(" ") { it.toString() }
Comment on lines -985 to -986
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before every table-row, there's an invisible link - I think it's used by the anchor link to focus on the right row. This property was used for the filter value in it, but I couldn't understand if it was actually needed to be present - made no difference upon testing.

2023-05-30_18-09-35


private val DisplaySourceSet.comparableKey
get() = sourceSetIDs.merged.let { it.scopeId + it.sourceSetName }
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ function refreshFiltering() {
document.querySelectorAll("[data-filterable-set]")
.forEach(
elem => {
let platformList = elem.getAttribute("data-filterable-set").split(' ').filter(v => -1 !== sourcesetList.indexOf(v))
elem.setAttribute("data-filterable-current", platformList.join(' '))
let platformList = elem.getAttribute("data-filterable-set").split(',').filter(v => -1 !== sourcesetList.indexOf(v))
elem.setAttribute("data-filterable-current", platformList.join(','))
}
)
refreshFilterButtons()
Expand Down
64 changes: 64 additions & 0 deletions plugins/base/src/test/kotlin/renderers/html/SourceSetFilterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package renderers.html

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import signatures.renderedContent
import utils.TestOutputWriterPlugin

class SourceSetFilterTest : BaseAbstractTest() {

@Test // see #3011
fun `should separate multiple data-filterable attribute values with comma`() {
val configuration = dokkaConfiguration {
moduleName = "Dokka Module"

sourceSets {
val common = sourceSet {
name = "common"
displayName = "common"
analysisPlatform = "common"
sourceRoots = listOf("src/commonMain/kotlin/testing/Test.kt")
}
sourceSet {
name = "jvm"
displayName = "jvm"
analysisPlatform = "jvm"
dependentSourceSets = setOf(common.value.sourceSetID)
sourceRoots = listOf("src/jvmMain/kotlin/testing/Test.kt")
}
}
}

val source = """
|/src/commonMain/kotlin/testing/Test.kt
|package testing
|
|expect open class Test
|
|/src/jvmMain/kotlin/testing/Test.kt
|package testing
|
|actual open class Test
""".trimIndent()

val writerPlugin = TestOutputWriterPlugin()
testInline(
source,
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
val packagePage = writerPlugin.writer.renderedContent("-dokka -module/testing/index.html")

val testClassRow = packagePage
.select("div[data-togglable=TYPE]")
.select("div[class=table-row]")
.single()

assertEquals("Dokka Module/common,Dokka Module/jvm", testClassRow.attr("data-filterable-current"))
assertEquals("Dokka Module/common,Dokka Module/jvm", testClassRow.attr("data-filterable-set"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import kotlinx.cli.delimiter

internal fun parseSourceSet(moduleName: String, args: Array<String>): DokkaConfiguration.DokkaSourceSet {

if (moduleName.contains(',')) {
// To figure out why this is needed and if it is still relevant, see the comment here:
// https://github.com/Kotlin/dokka/issues/3011#issuecomment-1568620493
throw IllegalArgumentException("Module name cannot contain commas as it is used internally as a delimiter.")
}

val parser = ArgParser("sourceSet", prefixStyle = ArgParser.OptionPrefixStyle.JVM)

val sourceSetName by parser.option(
Expand Down
6 changes: 6 additions & 0 deletions runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ abstract class AbstractDokkaMojo(private val defaultDokkaPlugins: List<Dependenc
}
}

if (moduleName.contains(',')) {
// To figure out why this is needed and if it is still relevant, see the comment here:
// https://github.com/Kotlin/dokka/issues/3011#issuecomment-1568620493
throw IllegalArgumentException("Module name cannot contain commas as it is used internally as a delimiter.")
}

fun defaultLinks(config: DokkaSourceSetImpl): Set<ExternalDocumentationLinkImpl> {
val links = mutableSetOf<ExternalDocumentationLinkImpl>()
if (!config.noJdkLink)
Expand Down