User: rednesto Date: 01 Aug 24 15:08 Revision: d74d95e782ef9ac5d8ee4dd54224e61f518561fb Summary: Make mods.toml support work with neoforge.mods.toml too TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=9531&personal=false Index: src/main/kotlin/platform/neoforge/util/NeoForgeConstants.kt =================================================================== --- src/main/kotlin/platform/neoforge/util/NeoForgeConstants.kt (revision 1801be074a48212f6a2c201299deb2a103737be2) +++ src/main/kotlin/platform/neoforge/util/NeoForgeConstants.kt (revision d74d95e782ef9ac5d8ee4dd54224e61f518561fb) @@ -30,4 +30,5 @@ const val NETWORK_MESSAGE = "net.neoforged.neoforge.network.simple.SimpleMessage" const val MCMOD_INFO = "mcmod.info" const val PACK_MCMETA = "pack.mcmeta" + const val MODS_TOML = "neoforge.mods.toml" } Index: src/main/kotlin/toml/platform/forge/ForgeTomlConstants.kt =================================================================== --- src/main/kotlin/toml/platform/forge/ForgeTomlConstants.kt (revision d74d95e782ef9ac5d8ee4dd54224e61f518561fb) +++ src/main/kotlin/toml/platform/forge/ForgeTomlConstants.kt (revision d74d95e782ef9ac5d8ee4dd54224e61f518561fb) @@ -0,0 +1,29 @@ +/* + * Minecraft Development for IntelliJ + * + * https://mcdev.io/ + * + * Copyright (C) 2024 minecraft-dev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, version 3.0 only. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.demonwav.mcdev.toml.platform.forge + +import com.demonwav.mcdev.platform.forge.util.ForgeConstants +import com.demonwav.mcdev.platform.neoforge.util.NeoForgeConstants + +object ForgeTomlConstants { + + val FILE_NAMES = setOf(ForgeConstants.MODS_TOML, NeoForgeConstants.MODS_TOML) +} Index: src/main/kotlin/toml/platform/forge/ModsTomlDocumentationProvider.kt =================================================================== --- src/main/kotlin/toml/platform/forge/ModsTomlDocumentationProvider.kt (revision 1801be074a48212f6a2c201299deb2a103737be2) +++ src/main/kotlin/toml/platform/forge/ModsTomlDocumentationProvider.kt (revision d74d95e782ef9ac5d8ee4dd54224e61f518561fb) @@ -20,7 +20,6 @@ package com.demonwav.mcdev.toml.platform.forge -import com.demonwav.mcdev.platform.forge.util.ForgeConstants import com.demonwav.mcdev.toml.TomlSchemaEntry import com.intellij.lang.documentation.DocumentationMarkup import com.intellij.lang.documentation.DocumentationProvider @@ -107,7 +106,7 @@ } private fun isModsToml(element: PsiElement?): Boolean = - element?.containingFile?.virtualFile?.name == ForgeConstants.MODS_TOML + element?.containingFile?.virtualFile?.name in ForgeTomlConstants.FILE_NAMES private class TomlSchemaKeyElement( val key: String, Index: src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt =================================================================== --- src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt (revision 1801be074a48212f6a2c201299deb2a103737be2) +++ src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt (revision d74d95e782ef9ac5d8ee4dd54224e61f518561fb) @@ -22,6 +22,7 @@ import com.demonwav.mcdev.platform.forge.util.ForgeConstants import com.demonwav.mcdev.toml.TomlElementVisitor +import com.demonwav.mcdev.toml.platform.forge.ForgeTomlConstants import com.demonwav.mcdev.toml.platform.forge.ModsTomlSchema import com.demonwav.mcdev.toml.stringValue import com.demonwav.mcdev.toml.tomlType @@ -53,14 +54,14 @@ override fun getStaticDescription(): String = "Checks mods.toml files for errors" override fun processFile(file: PsiFile, manager: InspectionManager): MutableList { - if (file.virtualFile.name == ForgeConstants.MODS_TOML) { + if (file.virtualFile.name in ForgeTomlConstants.FILE_NAMES) { return super.processFile(file, manager) } return mutableListOf() } override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { - if (holder.file.virtualFile.name == ForgeConstants.MODS_TOML) { + if (holder.file.virtualFile.name in ForgeTomlConstants.FILE_NAMES) { return Visitor(holder) } return PsiElementVisitor.EMPTY_VISITOR Index: src/main/kotlin/toml/toml-patterns.kt =================================================================== --- src/main/kotlin/toml/toml-patterns.kt (revision 1801be074a48212f6a2c201299deb2a103737be2) +++ src/main/kotlin/toml/toml-patterns.kt (revision d74d95e782ef9ac5d8ee4dd54224e61f518561fb) @@ -20,9 +20,10 @@ package com.demonwav.mcdev.toml -import com.demonwav.mcdev.platform.forge.util.ForgeConstants +import com.demonwav.mcdev.toml.platform.forge.ForgeTomlConstants import com.intellij.patterns.PlatformPatterns import com.intellij.patterns.PsiElementPattern +import com.intellij.patterns.StandardPatterns import com.intellij.patterns.VirtualFilePattern import com.intellij.psi.PsiElement import org.toml.lang.psi.TomlKey @@ -33,7 +34,8 @@ inline fun inModsToml(): PsiElementPattern.Capture = inModsToml(E::class.java) fun inModsToml(clazz: Class): PsiElementPattern.Capture = - PlatformPatterns.psiElement(clazz).inVirtualFile(VirtualFilePattern().withName(ForgeConstants.MODS_TOML)) + PlatformPatterns.psiElement(clazz) + .inVirtualFile(VirtualFilePattern().withName(StandardPatterns.string().oneOf(ForgeTomlConstants.FILE_NAMES))) fun inModsTomlKey(): PsiElementPattern.Capture = inModsToml().withParent(TomlKeySegment::class.java)