diff --git a/backend/build.gradle b/backend/build.gradle index a93bc0b..5fad940 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -28,7 +28,7 @@ configurations { } dependencies { - implementation("me.shedaniel:linkie-core:1.0.119") + implementation("me.shedaniel:linkie-core:1.0.120") implementation("io.ktor:ktor-server-cors:2.2.3") implementation("io.ktor:ktor-server-content-negotiation:2.2.3") implementation("io.ktor:ktor-server-status-pages:2.2.3") diff --git a/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieHandles.kt b/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieHandles.kt index 91c2c4d..859b9f1 100644 --- a/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieHandles.kt +++ b/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieHandles.kt @@ -1,10 +1,15 @@ package me.shedaniel.linkie.web +import com.soywiz.korio.async.launch +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.withContext import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.* import me.shedaniel.linkie.* +import me.shedaniel.linkie.namespaces.YarnNamespace import me.shedaniel.linkie.utils.MemberEntry import me.shedaniel.linkie.utils.ResultHolder import me.shedaniel.linkie.utils.toVersion @@ -17,6 +22,7 @@ import nl.adaptivity.xmlutil.serialization.XmlSerialName import java.io.File import kotlin.math.max import kotlin.math.min +import kotlin.properties.Delegates val xml = XML { autoPolymorphic = true @@ -50,16 +56,39 @@ suspend fun search( ?: (translateNamespace?.defaultVersion?.takeIf { it in allVersions } ?: allVersions.first()) val provider = version?.let { namespace.getProvider(it) } ?: namespace.getProvider(defaultVersion) - val mappings = provider.get() + var mappings by Delegates.notNull() + var yarnMappings: MappingsContainer? = null + coroutineScope { + launch { withContext(Dispatchers.Default) { mappings = provider.get() } } + if (!namespace.hasMethodArgs(provider.version!!) && provider.version!!.tryToVersion()?.takeIf { it > "1.14.4".toVersion() } != null) { + val yarnProvider = YarnNamespace.getProvider(provider.version!!) + if (!yarnProvider.isEmpty()) { + launch { withContext(Dispatchers.Default) { yarnMappings = yarnProvider.get() } } + } + } + } val result = MappingsQueryUtils.query(mappings, query, *buildList { if (allowClasses) add(MappingsEntryType.CLASS) if (allowMethods) add(MappingsEntryType.METHOD) if (allowFields) add(MappingsEntryType.FIELD) }.toTypedArray(), limit = limit) + val argMappings: (Class, Method) -> List? = if (yarnMappings != null) { + inner@{ clazz, method -> + val obfName = method.obfMergedName ?: return@inner null + val obfDesc = method.getObfMergedDesc(mappings) + val parentObfName = clazz.obfMergedName ?: return@inner null + val targetParent = yarnMappings!!.getClassByObfName(parentObfName) ?: return@inner null + val targetMethod = + targetParent.methods.firstOrNull { it.obfMergedName == obfName && it.getObfMergedDesc(yarnMappings!!) == obfDesc } + ?: return@inner null + + targetMethod.args + } + } else { _, _ -> null } if (translateNamespace == null) { return SearchResultEntries( entries = result.results.asSequence().take(limit).mapNotNull { - toJsonFromEntry(mappings, it.value, it.score) + toJsonFromEntry(namespace, mappings, it.value, it.score, argMappings) }.toList(), fuzzy = result.fuzzy, ) @@ -67,8 +96,8 @@ suspend fun search( val target = translateNamespace.getProvider(provider.version!!).get() val elements = mutableListOf() translate(mappings, target, result.results.asSequence().take(limit)) { from, to, score -> - toJsonFromEntry(mappings, from, score)?.also { obj -> - val translated = toJsonFromEntry(target, to, score) + toJsonFromEntry(namespace, mappings, from, score, argMappings)?.also { obj -> + val translated = toJsonFromEntry(translateNamespace, target, to, score) { _, _ -> null } if (translated == null) elements.add(obj) else { elements.add(buildJsonObject { @@ -190,7 +219,7 @@ fun getLoaderVersions(loader: String): MutableMap List?): JsonObject? { return when (entry) { is Class -> json.encodeToJsonElement( SearchResultClassEntry.serializer(), SearchResultClassEntry( @@ -204,7 +233,7 @@ fun toJsonFromEntry(mappings: MappingsContainer, entry: Any?, score: Double): Js ) ) as JsonObject - is MemberEntry<*> -> json.encodeToJsonElement( + is MemberEntry<*> -> (json.encodeToJsonElement( SearchResultMemberEntry.serializer(), SearchResultMemberEntry( obf = entry.member.obfMergedName, intermediary = entry.member.intermediaryName, @@ -224,7 +253,23 @@ fun toJsonFromEntry(mappings: MappingsContainer, entry: Any?, score: Double): Js score = score, memberType = if (entry.member is Field) "f" else "m" ) - ) as JsonObject + ) as JsonObject).let { + if (entry.member is Method) { + var guessed = false + val args = (entry.member as Method).args ?: (argMappings(entry.owner, entry.member as Method)?.also { + guessed = true + } ?: return@let it) + val map = it.toMutableMap() + map["p"] = buildJsonObject { + args.forEach { arg -> + put(arg.index.toString(), arg.name) + } + } + map["q"] = JsonPrimitive(guessed) + map["r"] = JsonPrimitive(!guessed && namespace.id.contains("mojang")) + JsonObject(map) + } else it + } else -> null } diff --git a/backend/src/main/kotlin/me/shedaniel/linkie/web/deps/Deps.kt b/backend/src/main/kotlin/me/shedaniel/linkie/web/deps/Deps.kt index 38fba27..12482be 100644 --- a/backend/src/main/kotlin/me/shedaniel/linkie/web/deps/Deps.kt +++ b/backend/src/main/kotlin/me/shedaniel/linkie/web/deps/Deps.kt @@ -166,6 +166,7 @@ fun startLinkie() { BarnNamespace, FeatherNamespace, ), + maximumLoadedVersions = 4, remapSourceDaemonDuration = 10.minutes, ) ) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 72d265e..1d95852 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -94,6 +94,7 @@ export default defineComponent({ \ No newline at end of file diff --git a/frontend/src/components/mappings/AutoBold.vue b/frontend/src/components/mappings/AutoBold.vue new file mode 100644 index 0000000..a1b2954 --- /dev/null +++ b/frontend/src/components/mappings/AutoBold.vue @@ -0,0 +1,55 @@ + + + \ No newline at end of file diff --git a/frontend/src/components/mappings/MappingsEntryBlock.vue b/frontend/src/components/mappings/MappingsEntryBlock.vue index 6c91ef6..25b30ed 100644 --- a/frontend/src/components/mappings/MappingsEntryBlock.vue +++ b/frontend/src/components/mappings/MappingsEntryBlock.vue @@ -30,6 +30,53 @@ +
+
+ + + + + + + + + +
+
+ + + + + + + Warning +
+ The method argument mappings are aggregated from other mapping projects,
+ and may not be accurate or fit the current context.

+ This may be the result of the lack of a proper source for this mappings or this version. +
+
+
+ + + + + + + Info +
+ The method argument mappings are provided from a community project, ParchmentMC,
+ and may not be accurate, or may be subject to a different license. +
+
+
+
+ {{ methodReturnType(entry) }} + {{ onlyClass(getOptimumName(entry)) }}( + {{ methodArgs(entry) }}) +
+