User: joe Date: 13 Apr 26 19:56 Revision: 5ea76a2fb417a03babdf5d02803223a362b0f5c4 Summary: Fix completion for CT headers and add annotation for unrecognized CT version TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=10514&personal=false Index: src/main/kotlin/platform/fabric/util/FabricConstants.kt =================================================================== --- src/main/kotlin/platform/fabric/util/FabricConstants.kt (revision 090a8f15f893813cfca9b0e91d1baa884935d93b) +++ src/main/kotlin/platform/fabric/util/FabricConstants.kt (revision 5ea76a2fb417a03babdf5d02803223a362b0f5c4) @@ -40,4 +40,7 @@ "server" to SERVER_MOD_INITIALIZER, "preLaunch" to PRE_LAUNCH_ENTRYPOINT ) + + // Effective class tweaker version (see CtHeaderMixin.effectiveVersion) + const val CLASS_TWEAKER_VERSION = 4 } Index: src/main/kotlin/platform/mcp/ct/CtAnnotator.kt =================================================================== --- src/main/kotlin/platform/mcp/ct/CtAnnotator.kt (revision 090a8f15f893813cfca9b0e91d1baa884935d93b) +++ src/main/kotlin/platform/mcp/ct/CtAnnotator.kt (revision 5ea76a2fb417a03babdf5d02803223a362b0f5c4) @@ -20,6 +20,7 @@ package com.demonwav.mcdev.platform.mcp.ct +import com.demonwav.mcdev.platform.fabric.util.FabricConstants import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtAccess import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtClassLiteral import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtExtendEnumEntry @@ -75,8 +76,24 @@ holder.newAnnotation(HighlightSeverity.ERROR, "'$target' cannot be used with '$access'").create() } } + is CtHeader -> { + val version = element.effectiveVersion + val versionElement = element.versionElement ?: return + when (element.nameString) { + "accessWidener" -> { + if (version == null || version < 1 || version > 2) { + holder.newAnnotation(HighlightSeverity.ERROR, "Unrecognized access widener version").range(versionElement).create() - } - } + } + } + "classTweaker" -> { + if (version == null || version < 3 || version > FabricConstants.CLASS_TWEAKER_VERSION) { + holder.newAnnotation(HighlightSeverity.ERROR, "Unrecognized class tweaker version").range(versionElement).create() + } + } + } + } + } + } object TokenSets { val compatibleByAccessMap = HashMultimap.create() Index: src/main/kotlin/platform/mcp/ct/CtCompletionContributor.kt =================================================================== --- src/main/kotlin/platform/mcp/ct/CtCompletionContributor.kt (revision 090a8f15f893813cfca9b0e91d1baa884935d93b) +++ src/main/kotlin/platform/mcp/ct/CtCompletionContributor.kt (revision 5ea76a2fb417a03babdf5d02803223a362b0f5c4) @@ -22,6 +22,7 @@ import com.demonwav.mcdev.facet.MinecraftFacet import com.demonwav.mcdev.platform.fabric.FabricModuleType +import com.demonwav.mcdev.platform.fabric.util.FabricConstants import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtTypes import com.demonwav.mcdev.util.findModule import com.intellij.codeInsight.completion.CodeCompletionHandlerBase @@ -31,6 +32,7 @@ import com.intellij.codeInsight.completion.CompletionResultSet import com.intellij.codeInsight.completion.CompletionType import com.intellij.codeInsight.completion.InsertionContext +import com.intellij.codeInsight.completion.PrioritizedLookupElement import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.openapi.application.runReadAction import com.intellij.patterns.PlatformPatterns @@ -68,6 +70,11 @@ } } +private val ADDITIONAL_NAMESPACE_PRIORITY = mapOf( + "named" to 0.2, + "official" to 0.1, +) + object CtHeaderCompletionProvider : CompletionProvider() { override fun addCompletions( @@ -76,12 +83,19 @@ result: CompletionResultSet, ) { if (parameters.position.prevLeaf(true) == null) { - result.addElement(LookupElementBuilder.create("accessWidener v1 named")) - result.addElement(LookupElementBuilder.create("accessWidener v2 named")) - result.addElement(LookupElementBuilder.create("classTweaker v1 named")) + val module = parameters.originalFile.findModule() ?: return + val fabricModule = MinecraftFacet.getInstance(module, FabricModuleType) ?: return + for (mappingNamespace in fabricModule.mappingNamespaces) { + val additionalPriority = ADDITIONAL_NAMESPACE_PRIORITY[mappingNamespace] ?: 0.0 + result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create("accessWidener v1 $mappingNamespace"), 1.0 + additionalPriority)) + result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create("accessWidener v2 $mappingNamespace"), 2.0 + additionalPriority)) + for (ctVersion in 1..FabricConstants.CLASS_TWEAKER_VERSION - 2) { + result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create("classTweaker v$ctVersion $mappingNamespace"), 2.0 + ctVersion + additionalPriority)) - } - } -} + } + } + } + } +} object CtNamespaceCompletionProvider : CompletionProvider() { Index: src/main/kotlin/platform/mcp/ct/psi/mixins/CtHeaderMixin.kt =================================================================== --- src/main/kotlin/platform/mcp/ct/psi/mixins/CtHeaderMixin.kt (revision 090a8f15f893813cfca9b0e91d1baa884935d93b) +++ src/main/kotlin/platform/mcp/ct/psi/mixins/CtHeaderMixin.kt (revision 5ea76a2fb417a03babdf5d02803223a362b0f5c4) @@ -21,11 +21,16 @@ package com.demonwav.mcdev.platform.mcp.ct.psi.mixins import com.demonwav.mcdev.platform.mcp.ct.psi.CtElement +import com.intellij.psi.PsiElement interface CtHeaderMixin : CtElement { + val nameElement: PsiElement val nameString: String + val versionElement: PsiElement? val versionString: String? + val namespaceElement: PsiElement? val namespaceString: String? + // Effective version, AW is 1 and 2; CT starts with 3, so CT v1 has effective version 3. val effectiveVersion: Int? } Index: src/main/kotlin/platform/mcp/ct/psi/mixins/impl/CtHeaderImplMixin.kt =================================================================== --- src/main/kotlin/platform/mcp/ct/psi/mixins/impl/CtHeaderImplMixin.kt (revision 090a8f15f893813cfca9b0e91d1baa884935d93b) +++ src/main/kotlin/platform/mcp/ct/psi/mixins/impl/CtHeaderImplMixin.kt (revision 5ea76a2fb417a03babdf5d02803223a362b0f5c4) @@ -32,14 +32,23 @@ private val LOG = logger() } + override val nameElement: PsiElement + get() = findNotNullChildByType(CtTypes.HEADER_NAME) + override val nameString: String - get() = findNotNullChildByType(CtTypes.HEADER_NAME).text + get() = nameElement.text + override val versionElement: PsiElement? + get() = findChildByType(CtTypes.HEADER_VERSION_ELEMENT) + override val versionString: String? - get() = findChildByType(CtTypes.HEADER_VERSION_ELEMENT)?.text + get() = versionElement?.text + override val namespaceElement: PsiElement? + get() = findChildByType(CtTypes.HEADER_NAMESPACE_ELEMENT) + override val namespaceString: String? - get() = findChildByType(CtTypes.HEADER_NAMESPACE_ELEMENT)?.text + get() = namespaceElement?.text override val effectiveVersion: Int? get() {