mirror of
https://github.com/apple/pkl.git
synced 2026-03-20 00:04:05 +01:00
Update Kotlin to 2.0 (#900)
- update Kotlin from 1.7.10 to 2.0.21
- Kotlin 1.6 dependencies in Gradle lock files are expected because kotlinc,
which is also used by some tests, internally uses some 1.6 dependencies
for backwards compatibility reasons.
- update kotlinx-html and kotlinx-serialization
- adapt Kotlin code where necessary
- use Kotlin stdlib Path APIs where possible
- fix IntelliJ Kotlin inspection warnings
- reformat code with `./gradlew spotlessApply`
- ktfmt adds lots of trailing commas
- Add workaround to fix IntelliJ "unresolved reference" errors
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,11 +18,7 @@ package org.pkl.doc
|
||||
import java.io.IOException
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.createSymbolicLinkPointingTo
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.isSameFileAs
|
||||
import org.pkl.commons.deleteRecursively
|
||||
import kotlin.io.path.*
|
||||
import org.pkl.core.ModuleSchema
|
||||
import org.pkl.core.PClassInfo
|
||||
import org.pkl.core.Version
|
||||
@@ -33,6 +29,7 @@ import org.pkl.core.util.IoUtils
|
||||
*
|
||||
* For the high-level Pkldoc API, see [CliDocGenerator].
|
||||
*/
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
class DocGenerator(
|
||||
/**
|
||||
* The documentation website to generate.
|
||||
@@ -62,7 +59,7 @@ class DocGenerator(
|
||||
* Generates source URLs with fixed line numbers `#L123-L456` to avoid churn in expected output
|
||||
* files (e.g., when stdlib line numbers change).
|
||||
*/
|
||||
private val isTestMode: Boolean = false
|
||||
private val isTestMode: Boolean = false,
|
||||
) {
|
||||
companion object {
|
||||
internal fun List<PackageData>.current(
|
||||
@@ -147,7 +144,7 @@ internal class DocPackage(val docPackageInfo: DocPackageInfo, val modules: List<
|
||||
|
||||
val minPklVersion: Version? by lazy { docModules.mapNotNull { it.minPklVersion }.maxOrNull() }
|
||||
|
||||
val deprecation: String? = docPackageInfo.annotations.deprecation
|
||||
@Suppress("unused") val deprecation: String? = docPackageInfo.annotations.deprecation
|
||||
|
||||
val isUnlisted: Boolean = docPackageInfo.annotations.isUnlisted
|
||||
|
||||
@@ -181,7 +178,7 @@ internal class DocPackage(val docPackageInfo: DocPackageInfo, val modules: List<
|
||||
docPackageInfo.version,
|
||||
docPackageInfo.getModuleImportUri(mod.moduleName),
|
||||
docPackageInfo.getModuleSourceCode(mod.moduleName),
|
||||
exampleModulesBySubject[mod.moduleName] ?: listOf()
|
||||
exampleModulesBySubject[mod.moduleName] ?: listOf(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -193,7 +190,7 @@ internal class DocModule(
|
||||
val version: String,
|
||||
val importUri: URI,
|
||||
val sourceUrl: URI?,
|
||||
val examples: List<ModuleSchema>
|
||||
val examples: List<ModuleSchema>,
|
||||
) {
|
||||
val name: String
|
||||
get() = schema.moduleName
|
||||
@@ -212,7 +209,7 @@ internal class DocModule(
|
||||
version?.let { Version.parse(it) }
|
||||
}
|
||||
|
||||
val deprecation: String? = schema.annotations.deprecation
|
||||
@Suppress("unused") val deprecation: String? = schema.annotations.deprecation
|
||||
|
||||
val isUnlisted: Boolean = schema.annotations.isUnlisted
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -101,14 +101,14 @@ data class DocPackageInfo(
|
||||
version = dependency["version"] as String,
|
||||
sourceCode = (dependency["sourceCode"] as String?)?.toUri(),
|
||||
sourceCodeUrlScheme = dependency["sourceCodeUrlScheme"] as String?,
|
||||
documentation = (dependency["documentation"] as String?)?.toUri()
|
||||
documentation = (dependency["documentation"] as String?)?.toUri(),
|
||||
)
|
||||
},
|
||||
overview = module["overview"] as String,
|
||||
overviewImports =
|
||||
(module["overviewImports"] as Map<String, String>).mapValues { it.value.toUri() },
|
||||
annotations = module["annotations"] as List<PObject>,
|
||||
extraAttributes = module["extraAttributes"] as Map<String, String>
|
||||
extraAttributes = module["extraAttributes"] as Map<String, String>,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ data class DocPackageInfo(
|
||||
dependency.name,
|
||||
dependency.uri,
|
||||
dependency.version,
|
||||
getModulePath(moduleName, dependency.prefix)
|
||||
getModulePath(moduleName, dependency.prefix),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ data class DocPackageInfo(
|
||||
version,
|
||||
getModulePath(moduleName, moduleNamePrefix),
|
||||
type.simpleName,
|
||||
isTypeAlias = type is TypeAlias
|
||||
isTypeAlias = type is TypeAlias,
|
||||
)
|
||||
}
|
||||
for (dependency in dependencies) {
|
||||
@@ -149,7 +149,7 @@ data class DocPackageInfo(
|
||||
dependency.version,
|
||||
getModulePath(moduleName, dependency.prefix),
|
||||
type.simpleName,
|
||||
isTypeAlias = type is TypeAlias
|
||||
isTypeAlias = type is TypeAlias,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -212,6 +212,7 @@ data class DocPackageInfo(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
internal fun getModuleSourceCode(moduleName: String): URI? =
|
||||
when {
|
||||
!moduleName.startsWith(prefix) -> null
|
||||
@@ -223,7 +224,7 @@ data class DocPackageInfo(
|
||||
|
||||
internal fun getModuleSourceCodeWithSourceLocation(
|
||||
moduleName: String,
|
||||
sourceLocation: SourceLocation
|
||||
sourceLocation: SourceLocation,
|
||||
): URI? {
|
||||
return when {
|
||||
!moduleName.startsWith(prefix) -> null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,12 +38,12 @@ internal fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
class DocCommand :
|
||||
BaseCommand(name = "pkldoc", helpLink = Release.current().documentation().homepage(), help = "") {
|
||||
BaseCommand(name = "pkldoc", helpLink = Release.current().documentation().homepage()) {
|
||||
|
||||
private val modules: List<URI> by
|
||||
argument(
|
||||
name = "<modules>",
|
||||
help = "Module paths/uris, or package uris to generate documentation for"
|
||||
help = "Module paths/uris, or package uris to generate documentation for",
|
||||
)
|
||||
.convert { parseModuleName(it) }
|
||||
.multiple(required = true)
|
||||
@@ -52,7 +52,7 @@ class DocCommand :
|
||||
option(
|
||||
names = arrayOf("-o", "--output-dir"),
|
||||
metavar = "<directory>",
|
||||
help = "Directory where generated documentation is placed."
|
||||
help = "Directory where generated documentation is placed.",
|
||||
)
|
||||
.path()
|
||||
.required()
|
||||
@@ -61,14 +61,7 @@ class DocCommand :
|
||||
|
||||
override fun run() {
|
||||
val options =
|
||||
CliDocGeneratorOptions(
|
||||
baseOptions.baseOptions(
|
||||
modules,
|
||||
projectOptions,
|
||||
),
|
||||
outputDir,
|
||||
true
|
||||
)
|
||||
CliDocGeneratorOptions(baseOptions.baseOptions(modules, projectOptions), outputDir, true)
|
||||
CliDocGenerator(options).run()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import kotlinx.html.*
|
||||
internal class MainPageGenerator(
|
||||
docsiteInfo: DocsiteInfo,
|
||||
private val packagesData: List<PackageData>,
|
||||
pageScope: SiteScope
|
||||
pageScope: SiteScope,
|
||||
) : MainOrPackagePageGenerator<SiteScope>(docsiteInfo, pageScope, pageScope) {
|
||||
override val html: HTML.() -> Unit = {
|
||||
renderHtmlHead()
|
||||
@@ -41,7 +41,7 @@ internal class MainPageGenerator(
|
||||
|
||||
renderMemberGroupLinks(
|
||||
Triple("Overview", "#_overview", memberDocs.isExpandable),
|
||||
Triple("Packages", "#_packages", packagesData.isNotEmpty())
|
||||
Triple("Packages", "#_packages", packagesData.isNotEmpty()),
|
||||
)
|
||||
|
||||
if (docsiteInfo.overview != null) {
|
||||
@@ -90,12 +90,12 @@ internal class MainPageGenerator(
|
||||
for (pkg in sortedPackages) {
|
||||
val packageScope =
|
||||
pageScope.packageScopes[pkg.ref.pkg]
|
||||
// create scope for previously generated package
|
||||
?: pageScope.createEmptyPackageScope(
|
||||
// create scope for previously generated package
|
||||
?: pageScope.createEmptyPackageScope(
|
||||
pkg.ref.pkg,
|
||||
pkg.ref.version,
|
||||
pkg.sourceCodeUrlScheme,
|
||||
pkg.sourceCode
|
||||
pkg.sourceCode,
|
||||
)
|
||||
|
||||
val memberDocs =
|
||||
@@ -103,7 +103,6 @@ internal class MainPageGenerator(
|
||||
pkg.summary,
|
||||
packageScope,
|
||||
listOfNotNull(pkg.deprecation?.let { createDeprecatedAnnotation(it) }),
|
||||
isDeclaration = false
|
||||
)
|
||||
|
||||
renderModuleOrPackage(pkg.ref.pkg, packageScope, memberDocs)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,7 +41,7 @@ internal class MarkdownParserFactory(private val pageScope: DocScope) : InlinePa
|
||||
internal class MarkdownParserContext(
|
||||
private val docScope: DocScope,
|
||||
private val pageScope: DocScope,
|
||||
private val delegate: InlineParserContext
|
||||
private val delegate: InlineParserContext,
|
||||
) : InlineParserContext {
|
||||
companion object {
|
||||
private val keywords = setOf("null", "true", "false", "this", "unknown", "nothing")
|
||||
@@ -54,7 +54,7 @@ internal class MarkdownParserContext(
|
||||
}
|
||||
|
||||
override fun <D : Any> getDefinition(type: Class<D>, label: String): D? {
|
||||
@Suppress("UNCHECKED_CAST", "DEPRECATION")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return when (type) {
|
||||
LinkReferenceDefinition::class.java -> getLinkReferenceDefinition(label) as D
|
||||
else -> null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,14 +22,14 @@ internal class ModulePageGenerator(
|
||||
docPackage: DocPackage,
|
||||
docModule: DocModule,
|
||||
pageScope: ModuleScope,
|
||||
isTestMode: Boolean
|
||||
isTestMode: Boolean,
|
||||
) :
|
||||
ModuleOrClassPageGenerator<ModuleScope>(
|
||||
docsiteInfo,
|
||||
docModule,
|
||||
docModule.schema.moduleClass,
|
||||
pageScope,
|
||||
isTestMode
|
||||
isTestMode,
|
||||
) {
|
||||
private val module = docModule.schema
|
||||
|
||||
@@ -61,7 +61,7 @@ internal class ModulePageGenerator(
|
||||
pageScope,
|
||||
clazz.annotations,
|
||||
isDeclaration = true,
|
||||
collectMemberInfo(docModule)
|
||||
collectMemberInfo(docModule),
|
||||
)
|
||||
|
||||
renderMemberGroupLinks(
|
||||
@@ -69,7 +69,7 @@ internal class ModulePageGenerator(
|
||||
Triple("Properties", "#_properties", clazz.hasListedProperty),
|
||||
Triple("Methods", "#_methods", clazz.hasListedMethod),
|
||||
Triple("Classes", "#_classes", module.hasListedClass),
|
||||
Triple("Type Aliases", "#_type-aliases", module.hasListedTypeAlias)
|
||||
Triple("Type Aliases", "#_type-aliases", module.hasListedTypeAlias),
|
||||
)
|
||||
|
||||
renderAnchor("_overview")
|
||||
@@ -234,13 +234,12 @@ internal class ModulePageGenerator(
|
||||
"inherited",
|
||||
"expandable",
|
||||
"hidden",
|
||||
"collapsed"
|
||||
"collapsed",
|
||||
)
|
||||
} else setOf("member", "with-page-link")
|
||||
|
||||
val classScope = ClassScope(clazz, pageScope.url, pageScope)
|
||||
val memberDocs =
|
||||
MemberDocs(clazz.docComment, classScope, clazz.annotations, isDeclaration = false)
|
||||
val memberDocs = MemberDocs(clazz.docComment, classScope, clazz.annotations)
|
||||
|
||||
memberDocs.renderExpandIcon(this)
|
||||
renderSelfLink(className)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,11 +18,10 @@ package org.pkl.doc
|
||||
import java.io.IOException
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import kotlin.io.path.writer
|
||||
import kotlin.streams.toList
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.pkl.commons.createParentDirectories
|
||||
import org.pkl.commons.readString
|
||||
import org.pkl.commons.toUri
|
||||
import org.pkl.commons.walk
|
||||
@@ -88,7 +87,7 @@ internal data class PackageRef(
|
||||
override val pkgUri: @Contextual URI?,
|
||||
|
||||
/** The package version. */
|
||||
override val version: String
|
||||
override val version: String,
|
||||
) : ElementRef() {
|
||||
override val pageUrl: URI by lazy { "$pkg/$version/index.html".toUri() }
|
||||
}
|
||||
@@ -106,7 +105,7 @@ internal data class ModuleRef(
|
||||
override val version: String,
|
||||
|
||||
/** The module path. */
|
||||
val module: String
|
||||
val module: String,
|
||||
) : ElementRef() {
|
||||
override val pageUrl: URI by lazy { "$pkg/$version/$module/index.html".toUri() }
|
||||
|
||||
@@ -138,7 +137,7 @@ internal data class TypeRef(
|
||||
val type: String,
|
||||
|
||||
/** Whether this is a type alias rather than a class. */
|
||||
val isTypeAlias: Boolean = false
|
||||
val isTypeAlias: Boolean = false,
|
||||
) : ElementRef() {
|
||||
|
||||
val id: TypeId by lazy { TypeId(pkg, module, type) }
|
||||
@@ -191,7 +190,7 @@ internal class PackageData(
|
||||
val dependencies: List<DependencyData> = listOf(),
|
||||
|
||||
/** The modules in this package. */
|
||||
val modules: List<ModuleData> = listOf()
|
||||
val modules: List<ModuleData> = listOf(),
|
||||
) {
|
||||
companion object {
|
||||
val json = Json { serializersModule = serializers }
|
||||
@@ -221,7 +220,7 @@ internal class PackageData(
|
||||
pkg.docPackageInfo.sourceCode,
|
||||
pkg.docPackageInfo.sourceCodeUrlScheme,
|
||||
pkg.docPackageInfo.dependencies.map { DependencyData(PackageRef(it.name, it.uri, it.version)) },
|
||||
pkg.docModules.mapNotNull { if (it.isUnlisted) null else ModuleData(pkg, it) }
|
||||
pkg.docModules.mapNotNull { if (it.isUnlisted) null else ModuleData(pkg, it) },
|
||||
)
|
||||
|
||||
fun write(path: Path) {
|
||||
@@ -255,7 +254,7 @@ internal class ModuleData(
|
||||
val ref: ModuleRef,
|
||||
|
||||
/** The first paragraph of the overview documentation for this module. */
|
||||
val summary: String? = null,
|
||||
@Suppress("unused") val summary: String? = null,
|
||||
|
||||
/** The deprecation message, or `null` if this module isn't deprecated. */
|
||||
val deprecation: String? = null,
|
||||
@@ -270,11 +269,11 @@ internal class ModuleData(
|
||||
val classes: List<ClassData> = listOf(),
|
||||
|
||||
/** The type aliases declared in this module. */
|
||||
val typeAliases: List<TypeAliasData> = listOf()
|
||||
@Suppress("unused") val typeAliases: List<TypeAliasData> = listOf(),
|
||||
) {
|
||||
constructor(
|
||||
pkg: DocPackage,
|
||||
module: DocModule
|
||||
module: DocModule,
|
||||
) : this(
|
||||
ModuleRef(pkg.name, pkg.uri, pkg.version, module.path),
|
||||
getDocCommentSummary(module.overview),
|
||||
@@ -289,7 +288,7 @@ internal class ModuleData(
|
||||
},
|
||||
module.schema.typeAliases.mapNotNull {
|
||||
if (it.value.isUnlisted) null else TypeAliasData(pkg, module, it.value)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -321,14 +320,14 @@ internal class ClassData(
|
||||
constructor(
|
||||
pkg: DocPackage,
|
||||
module: DocModule,
|
||||
clazz: PClass
|
||||
clazz: PClass,
|
||||
) : this(
|
||||
TypeRef(pkg.name, pkg.uri, pkg.version, module.path, clazz.simpleName),
|
||||
generateSequence(clazz.superclass) { it.superclass }
|
||||
.map { pkg.docPackageInfo.getTypeRef(it) }
|
||||
.filterNotNull()
|
||||
.toList(),
|
||||
findTypesUsedBy(clazz, pkg.docPackageInfo).toList()
|
||||
findTypesUsedBy(clazz, pkg.docPackageInfo).toList(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -339,15 +338,15 @@ internal class TypeAliasData(
|
||||
override val ref: TypeRef,
|
||||
|
||||
/** The types used by this type alias. */
|
||||
override val usedTypes: List<TypeRef> = listOf()
|
||||
override val usedTypes: List<TypeRef> = listOf(),
|
||||
) : TypeData() {
|
||||
constructor(
|
||||
pkg: DocPackage,
|
||||
module: DocModule,
|
||||
alias: TypeAlias
|
||||
alias: TypeAlias,
|
||||
) : this(
|
||||
TypeRef(pkg.name, pkg.uri, pkg.version, module.path, alias.simpleName, isTypeAlias = true),
|
||||
findTypesUsedBy(alias, pkg.docPackageInfo).toList()
|
||||
findTypesUsedBy(alias, pkg.docPackageInfo).toList(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -381,7 +380,7 @@ private fun findTypesUsedBy(
|
||||
type: PType,
|
||||
enclosingType: Member /* PClass|TypeAlias */,
|
||||
enclosingPackage: DocPackageInfo,
|
||||
result: MutableSet<TypeRef>
|
||||
result: MutableSet<TypeRef>,
|
||||
) {
|
||||
when (type) {
|
||||
is PType.Class -> {
|
||||
@@ -416,7 +415,7 @@ private fun findTypesUsedBy(
|
||||
enclosingPackage.uri,
|
||||
enclosingPackage.version,
|
||||
enclosingType.moduleName.substring(enclosingPackage.name.length + 1).replace('.', '/'),
|
||||
PClassInfo.MODULE_CLASS_NAME
|
||||
PClassInfo.MODULE_CLASS_NAME,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import kotlinx.html.*
|
||||
internal class PackagePageGenerator(
|
||||
docsiteInfo: DocsiteInfo,
|
||||
private val docPackage: DocPackage,
|
||||
pageScope: PackageScope
|
||||
pageScope: PackageScope,
|
||||
) : MainOrPackagePageGenerator<PackageScope>(docsiteInfo, pageScope, pageScope.parent) {
|
||||
override val html: HTML.() -> Unit = {
|
||||
renderHtmlHead()
|
||||
@@ -50,12 +50,12 @@ internal class PackagePageGenerator(
|
||||
pageScope,
|
||||
packageInfo.annotations,
|
||||
isDeclaration = true,
|
||||
collectMemberInfoForPackage(docPackage)
|
||||
collectMemberInfoForPackage(docPackage),
|
||||
)
|
||||
|
||||
renderMemberGroupLinks(
|
||||
Triple("Overview", "#_overview", memberDocs.isExpandable),
|
||||
Triple("Modules", "#_modules", docPackage.hasListedModule)
|
||||
Triple("Modules", "#_modules", docPackage.hasListedModule),
|
||||
)
|
||||
|
||||
renderAnchor("_overview")
|
||||
@@ -120,8 +120,7 @@ internal class PackagePageGenerator(
|
||||
module.docComment,
|
||||
moduleScope,
|
||||
module.annotations,
|
||||
isDeclaration = false,
|
||||
collectMemberInfo(docModule)
|
||||
extraMemberInfo = collectMemberInfo(docModule),
|
||||
)
|
||||
|
||||
renderModuleOrPackage(module.moduleName, moduleScope, memberDocs)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,19 +16,19 @@
|
||||
package org.pkl.doc
|
||||
|
||||
import kotlin.io.path.bufferedWriter
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import kotlinx.html.*
|
||||
import kotlinx.html.stream.appendHTML
|
||||
import org.commonmark.ext.gfm.tables.TablesExtension
|
||||
import org.commonmark.parser.Parser
|
||||
import org.commonmark.renderer.html.HtmlRenderer
|
||||
import org.pkl.commons.createParentDirectories
|
||||
import org.pkl.commons.toPath
|
||||
import org.pkl.core.*
|
||||
import org.pkl.core.util.IoUtils
|
||||
|
||||
internal abstract class PageGenerator<out S>(
|
||||
protected val docsiteInfo: DocsiteInfo,
|
||||
protected val pageScope: S
|
||||
protected val pageScope: S,
|
||||
) where S : PageScope {
|
||||
private val markdownInlineParserFactory = MarkdownParserFactory(pageScope)
|
||||
|
||||
@@ -110,7 +110,7 @@ internal abstract class PageGenerator<out S>(
|
||||
packageName: String?,
|
||||
packageVersion: String?,
|
||||
moduleName: String?,
|
||||
className: String?
|
||||
className: String?,
|
||||
) {
|
||||
header {
|
||||
if (docsiteInfo.title != null) {
|
||||
@@ -227,11 +227,11 @@ internal abstract class PageGenerator<out S>(
|
||||
) {
|
||||
ul {
|
||||
classes = setOf("member-group-links")
|
||||
for ((name, _href, show) in groups) {
|
||||
for ((name, href, show) in groups) {
|
||||
if (show) {
|
||||
li {
|
||||
a {
|
||||
href = _href
|
||||
this.href = href
|
||||
+name
|
||||
}
|
||||
}
|
||||
@@ -280,7 +280,7 @@ internal abstract class PageGenerator<out S>(
|
||||
|
||||
protected fun HtmlBlockTag.renderTypeAliasName(
|
||||
typeAlias: TypeAlias,
|
||||
cssClass: String = "name-ref"
|
||||
cssClass: String = "name-ref",
|
||||
) {
|
||||
val moduleDocUrl = pageScope.resolveModuleNameToDocUrl(typeAlias.moduleName)
|
||||
|
||||
@@ -302,7 +302,7 @@ internal abstract class PageGenerator<out S>(
|
||||
protected fun HtmlBlockTag.renderType(
|
||||
type: PType,
|
||||
currScope: DocScope,
|
||||
isNested: Boolean = false
|
||||
isNested: Boolean = false,
|
||||
) {
|
||||
when (type) {
|
||||
PType.UNKNOWN -> {
|
||||
@@ -390,7 +390,7 @@ internal abstract class PageGenerator<out S>(
|
||||
|
||||
private fun HtmlBlockTag.renderTypeVariable(
|
||||
typeVariable: PType.TypeVariable,
|
||||
currentScope: DocScope
|
||||
currentScope: DocScope,
|
||||
) {
|
||||
val parameterScope = currentScope.resolveVariable(typeVariable.name) as? ParameterScope
|
||||
|
||||
@@ -634,7 +634,7 @@ internal abstract class PageGenerator<out S>(
|
||||
annotations: List<PObject>,
|
||||
/** Whether these member docs are for the main declaration at the top of a page. */
|
||||
private val isDeclaration: Boolean = false,
|
||||
private val extraMemberInfo: Map<MemberInfoKey, HtmlBlockTag.() -> Unit> = mapOf()
|
||||
private val extraMemberInfo: Map<MemberInfoKey, HtmlBlockTag.() -> Unit> = mapOf(),
|
||||
) {
|
||||
init {
|
||||
markdownInlineParserFactory.docScope = docScope
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,15 @@
|
||||
package org.pkl.doc
|
||||
|
||||
import java.nio.file.Path
|
||||
import org.pkl.commons.deleteRecursively
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.deleteRecursively
|
||||
import org.pkl.core.util.json.JsonWriter
|
||||
|
||||
// Note: we don't currently make use of persisted type alias data (needs more thought).
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
internal class RuntimeDataGenerator(
|
||||
private val descendingVersionComparator: Comparator<String>,
|
||||
private val outputDir: Path
|
||||
private val outputDir: Path,
|
||||
) {
|
||||
|
||||
private val packageVersions = mutableMapOf<PackageId, MutableSet<String>>()
|
||||
@@ -95,7 +97,7 @@ internal class RuntimeDataGenerator(
|
||||
packageVersions.getOrDefault(ref.pkg, setOf()).sortedWith(descendingVersionComparator),
|
||||
{ it },
|
||||
{ if (it == ref.version) null else ref.copy(version = it).pageUrlRelativeTo(ref) },
|
||||
{ if (it == ref.version) CssConstants.CURRENT_VERSION else null }
|
||||
{ if (it == ref.version) CssConstants.CURRENT_VERSION else null },
|
||||
)
|
||||
writer.writeLinks(
|
||||
HtmlConstants.KNOWN_USAGES,
|
||||
@@ -104,7 +106,7 @@ internal class RuntimeDataGenerator(
|
||||
},
|
||||
PackageRef::pkg,
|
||||
{ it.pageUrlRelativeTo(ref) },
|
||||
{ null }
|
||||
{ null },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +124,7 @@ internal class RuntimeDataGenerator(
|
||||
moduleVersions.getOrDefault(ref.id, setOf()).sortedWith(descendingVersionComparator),
|
||||
{ it },
|
||||
{ if (it == ref.version) null else ref.copy(version = it).pageUrlRelativeTo(ref) },
|
||||
{ if (it == ref.version) CssConstants.CURRENT_VERSION else null }
|
||||
{ if (it == ref.version) CssConstants.CURRENT_VERSION else null },
|
||||
)
|
||||
writer.writeLinks(
|
||||
HtmlConstants.KNOWN_USAGES,
|
||||
@@ -131,7 +133,7 @@ internal class RuntimeDataGenerator(
|
||||
},
|
||||
TypeRef::displayName,
|
||||
{ it.pageUrlRelativeTo(ref) },
|
||||
{ null }
|
||||
{ null },
|
||||
)
|
||||
writer.writeLinks(
|
||||
HtmlConstants.KNOWN_SUBTYPES,
|
||||
@@ -140,7 +142,7 @@ internal class RuntimeDataGenerator(
|
||||
},
|
||||
TypeRef::displayName,
|
||||
{ it.pageUrlRelativeTo(ref) },
|
||||
{ null }
|
||||
{ null },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -158,7 +160,7 @@ internal class RuntimeDataGenerator(
|
||||
classVersions.getOrDefault(ref.id, setOf()).sortedWith(descendingVersionComparator),
|
||||
{ it },
|
||||
{ if (it == ref.version) null else ref.copy(version = it).pageUrlRelativeTo(ref) },
|
||||
{ if (it == ref.version) CssConstants.CURRENT_VERSION else null }
|
||||
{ if (it == ref.version) CssConstants.CURRENT_VERSION else null },
|
||||
)
|
||||
writer.writeLinks(
|
||||
HtmlConstants.KNOWN_USAGES,
|
||||
@@ -167,7 +169,7 @@ internal class RuntimeDataGenerator(
|
||||
},
|
||||
TypeRef::displayName,
|
||||
{ it.pageUrlRelativeTo(ref) },
|
||||
{ null }
|
||||
{ null },
|
||||
)
|
||||
writer.writeLinks(
|
||||
HtmlConstants.KNOWN_SUBTYPES,
|
||||
@@ -176,7 +178,7 @@ internal class RuntimeDataGenerator(
|
||||
},
|
||||
TypeRef::displayName,
|
||||
{ it.pageUrlRelativeTo(ref) },
|
||||
{ null }
|
||||
{ null },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -191,7 +193,7 @@ internal class RuntimeDataGenerator(
|
||||
// link href
|
||||
href: (T) -> String?,
|
||||
// link CSS classes
|
||||
classes: (T) -> String?
|
||||
classes: (T) -> String?,
|
||||
) {
|
||||
if (items.isEmpty()) return
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,7 @@ package org.pkl.doc
|
||||
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.bufferedWriter
|
||||
import org.pkl.commons.createParentDirectories
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import org.pkl.core.Member
|
||||
import org.pkl.core.PClass.Method
|
||||
import org.pkl.core.PClass.Property
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,8 +19,8 @@ import java.io.InputStream
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.bufferedWriter
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import kotlin.io.path.outputStream
|
||||
import org.pkl.commons.createParentDirectories
|
||||
import org.pkl.core.*
|
||||
import org.pkl.core.parser.Lexer
|
||||
import org.pkl.core.util.IoUtils
|
||||
@@ -62,7 +62,7 @@ internal val List<PObject>.isUnlisted: Boolean
|
||||
internal val List<PObject>.deprecation: String?
|
||||
get() = find { it.classInfo == PClassInfo.Deprecated }?.get("message") as String?
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Suppress("UNCHECKED_CAST", "unused")
|
||||
internal val List<PObject>.alsoKnownAs: List<String>?
|
||||
get() = find { it.classInfo == PClassInfo.AlsoKnownAs }?.get("names") as List<String>?
|
||||
|
||||
@@ -111,7 +111,7 @@ internal inline fun JsonWriter.array(body: JsonWriter.() -> Unit) {
|
||||
|
||||
internal fun String.replaceSourceCodePlaceholders(
|
||||
path: String,
|
||||
sourceLocation: Member.SourceLocation
|
||||
sourceLocation: Member.SourceLocation,
|
||||
): String {
|
||||
return replace("%{path}", path)
|
||||
.replace("%{line}", sourceLocation.startLine().toString())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,6 @@ import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
import org.pkl.commons.cli.CliBaseOptions
|
||||
import org.pkl.commons.cli.CliException
|
||||
import org.pkl.commons.createParentDirectories
|
||||
import org.pkl.commons.readString
|
||||
import org.pkl.commons.test.FileTestUtils
|
||||
import org.pkl.commons.test.PackageServer
|
||||
@@ -106,12 +105,7 @@ class CliDocGeneratorTest {
|
||||
actualOutputFiles.map { IoUtils.toNormalizedPathString(actualOutputDir.relativize(it)) }
|
||||
}
|
||||
|
||||
private val binaryFileExtensions =
|
||||
setOf(
|
||||
"woff2",
|
||||
"png",
|
||||
"svg",
|
||||
)
|
||||
private val binaryFileExtensions = setOf("woff2", "png", "svg")
|
||||
|
||||
private fun runDocGenerator(outputDir: Path, cacheDir: Path?) {
|
||||
CliDocGenerator(
|
||||
@@ -127,10 +121,10 @@ class CliDocGeneratorTest {
|
||||
URI("package://localhost:0/unlisted@1.0.0"),
|
||||
URI("package://localhost:0/deprecated@1.0.0"),
|
||||
) + package1InputModules + package2InputModules,
|
||||
moduleCacheDir = cacheDir
|
||||
moduleCacheDir = cacheDir,
|
||||
),
|
||||
outputDir = outputDir,
|
||||
isTestMode = true
|
||||
isTestMode = true,
|
||||
)
|
||||
)
|
||||
.run()
|
||||
@@ -172,7 +166,7 @@ class CliDocGeneratorTest {
|
||||
CliDocGeneratorOptions(
|
||||
CliBaseOptions(sourceModules = listOf(descriptor1.toUri(), descriptor2.toUri())),
|
||||
outputDir = tmpOutputDir,
|
||||
isTestMode = true
|
||||
isTestMode = true,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -192,7 +186,7 @@ class CliDocGeneratorTest {
|
||||
CliDocGeneratorOptions(
|
||||
CliBaseOptions(sourceModules = listOf(module1.toUri())),
|
||||
outputDir = tmpOutputDir,
|
||||
isTestMode = true
|
||||
isTestMode = true,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -212,7 +206,7 @@ class CliDocGeneratorTest {
|
||||
CliDocGeneratorOptions(
|
||||
CliBaseOptions(sourceModules = listOf(descriptor1.toUri())),
|
||||
outputDir = tmpOutputDir,
|
||||
isTestMode = true
|
||||
isTestMode = true,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -286,17 +280,14 @@ class CliDocGeneratorTest {
|
||||
sourceCode = URI.create("foo.pkl"),
|
||||
issueTracker = URI.create("https://github.com/apple/pkl/issues"),
|
||||
overview = "my overview",
|
||||
sourceCodeUrlScheme = "https://example.com/blob/$version%{path}#L%{line}-%{endLine}"
|
||||
sourceCodeUrlScheme = "https://example.com/blob/$version%{path}#L%{line}-%{endLine}",
|
||||
),
|
||||
modules = emptyList()
|
||||
),
|
||||
modules = emptyList(),
|
||||
)
|
||||
)
|
||||
|
||||
val packages: List<PackageData> =
|
||||
listOf(
|
||||
createPackageData("1.2.3"),
|
||||
createPackageData("1.3.0-SNAPSHOT"),
|
||||
)
|
||||
listOf(createPackageData("1.2.3"), createPackageData("1.3.0-SNAPSHOT"))
|
||||
val comparator =
|
||||
Comparator<String> { v1, v2 -> Version.parse(v1).compareTo(Version.parse(v2)) }.reversed()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user