mirror of
https://github.com/apple/pkl.git
synced 2026-04-26 02:08:39 +02:00
Fix tracking of known usages/subtypes (#1241)
Fixes an issue where known subtype/usage information is not gathered. Also: change class RuntimeData to not return pairs for better composability.
This commit is contained in:
@@ -84,8 +84,8 @@ internal data class RuntimeData(
|
||||
myRef: T,
|
||||
versions: Set<String>?,
|
||||
comparator: Comparator<String>,
|
||||
): Pair<RuntimeData, Boolean> {
|
||||
if (versions == null) return this to false
|
||||
): RuntimeData {
|
||||
if (versions == null) return this
|
||||
val newEffectiveVersions = knownVersions.mapTo(mutableSetOf()) { it.text } + versions
|
||||
val knownVersions =
|
||||
newEffectiveVersions
|
||||
@@ -93,9 +93,9 @@ internal data class RuntimeData(
|
||||
.map { version -> RuntimeDataLink(text = version, href = myRef.pageUrlForVersion(version)) }
|
||||
.toSet()
|
||||
if (knownVersions == this.knownVersions) {
|
||||
return this to false
|
||||
return this
|
||||
}
|
||||
return copy(knownVersions = knownVersions) to true
|
||||
return copy(knownVersions = knownVersions)
|
||||
}
|
||||
|
||||
fun <T : ElementRef<*>> addKnownUsages(
|
||||
@@ -103,8 +103,8 @@ internal data class RuntimeData(
|
||||
refs: Collection<T>?,
|
||||
text: (T) -> String,
|
||||
comparator: Comparator<String>,
|
||||
): Pair<RuntimeData, Boolean> {
|
||||
if (refs == null) return this to false
|
||||
): RuntimeData {
|
||||
if (refs == null) return this
|
||||
val newLinks =
|
||||
refs.mapTo(mutableSetOf()) { ref ->
|
||||
RuntimeDataLink(text = text(ref), href = ref.pageUrlRelativeTo(myRef))
|
||||
@@ -112,27 +112,27 @@ internal data class RuntimeData(
|
||||
val knownUsages =
|
||||
(this.knownUsages + newLinks).distinctByCommparator(comparator).sortedBy { it.text }.toSet()
|
||||
if (knownUsages == this.knownUsages) {
|
||||
return this to false
|
||||
return this
|
||||
}
|
||||
return copy(knownUsages = knownUsages) to true
|
||||
return copy(knownUsages = knownUsages)
|
||||
}
|
||||
|
||||
fun addKnownSubtypes(
|
||||
myRef: TypeRef,
|
||||
subtypes: Collection<TypeRef>?,
|
||||
comparator: Comparator<String>,
|
||||
): Pair<RuntimeData, Boolean> {
|
||||
if (subtypes == null) return this to false
|
||||
): RuntimeData {
|
||||
if (subtypes == null) return this
|
||||
val newLinks =
|
||||
subtypes.mapTo(mutableSetOf()) { ref ->
|
||||
RuntimeDataLink(text = ref.displayName, href = ref.pageUrlRelativeTo(myRef))
|
||||
}
|
||||
val knownSubtypes =
|
||||
(this.knownUsages + newLinks).distinctByCommparator(comparator).sortedBy { it.text }.toSet()
|
||||
(this.knownSubtypes + newLinks).distinctByCommparator(comparator).sortedBy { it.text }.toSet()
|
||||
if (knownSubtypes == this.knownSubtypes) {
|
||||
return this to false
|
||||
return this
|
||||
}
|
||||
return copy(knownSubtypes = knownSubtypes) to true
|
||||
return copy(knownSubtypes = knownSubtypes)
|
||||
}
|
||||
|
||||
fun Collection<RuntimeDataLink>.distinctByCommparator(
|
||||
@@ -156,5 +156,5 @@ internal data class RuntimeData(
|
||||
|
||||
fun perPackage(): RuntimeData = copy(knownUsages = setOf(), knownSubtypes = setOf())
|
||||
|
||||
fun perPackageVersion(): RuntimeData = RuntimeData(knownVersions = setOf())
|
||||
fun perPackageVersion(): RuntimeData = copy(knownVersions = setOf())
|
||||
}
|
||||
|
||||
@@ -126,14 +126,10 @@ internal class RuntimeDataGenerator(
|
||||
// we must not have this package in our docsite.
|
||||
if (!runtimeDataPath.isRegularFile()) return@launch
|
||||
val usages = packageUsages[ref]
|
||||
val (data, hasNewData) =
|
||||
ref.existingPerPackageVersionRuntimeData.addKnownUsages(
|
||||
ref,
|
||||
usages,
|
||||
PackageRef::pkg,
|
||||
descendingVersionComparator,
|
||||
)
|
||||
if (hasNewData) {
|
||||
val existingData = ref.existingPerPackageVersionRuntimeData
|
||||
val data =
|
||||
existingData.addKnownUsages(ref, usages, PackageRef::pkg, descendingVersionComparator)
|
||||
if (data != existingData) {
|
||||
data.doWriteTo(outputDir.resolve(ref.perPackageVersionRuntimeDataPath))
|
||||
}
|
||||
}
|
||||
@@ -172,7 +168,7 @@ internal class RuntimeDataGenerator(
|
||||
private fun writePackageFile(packageData: PackageData) {
|
||||
val ref = packageData.ref
|
||||
val newVersions = packageVersions[packageData.ref.pkg]?.mapTo(mutableSetOf()) { it.version }
|
||||
val (data, _) =
|
||||
val data =
|
||||
ref.existingPerPackageRuntimeData.addKnownVersions(
|
||||
ref,
|
||||
newVersions,
|
||||
@@ -183,7 +179,7 @@ internal class RuntimeDataGenerator(
|
||||
|
||||
private fun writePackageFilePerVersion(packageData: PackageData) {
|
||||
val ref = packageData.ref
|
||||
val (data, _) =
|
||||
val data =
|
||||
ref.existingPerPackageVersionRuntimeData.addKnownUsages(
|
||||
ref,
|
||||
packageUsages[ref],
|
||||
@@ -196,7 +192,7 @@ internal class RuntimeDataGenerator(
|
||||
private fun writeClassFile(classData: ClassData) {
|
||||
val ref = classData.ref
|
||||
val newVersions = classVersions[ref.id]?.mapTo(mutableSetOf()) { it }
|
||||
val (data, _) =
|
||||
val data =
|
||||
ref.existingPerPackageRuntimeData.addKnownVersions(
|
||||
ref,
|
||||
newVersions,
|
||||
@@ -208,12 +204,11 @@ internal class RuntimeDataGenerator(
|
||||
private fun writeClassFilePerVersion(classData: ClassData) {
|
||||
val ref = classData.ref
|
||||
val newSubtypes = subtypes[ref]
|
||||
val (data, _) =
|
||||
ref.existingPerPackageVersionRuntimeData.addKnownSubtypes(
|
||||
ref,
|
||||
newSubtypes,
|
||||
descendingVersionComparator,
|
||||
)
|
||||
val newUsages = typeUsages[ref]
|
||||
val data =
|
||||
ref.existingPerPackageVersionRuntimeData
|
||||
.addKnownSubtypes(ref, newSubtypes, descendingVersionComparator)
|
||||
.addKnownUsages(ref, newUsages, TypeRef::displayName, descendingVersionComparator)
|
||||
data.writePerPackageVersion(ref)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user