User: rednesto Date: 16 Jan 24 17:10 Revision: 59677b86ece5864084819bbbe3c616636e9d37f8 Summary: Generate mods.toml with quoted mod_id placeholders Fixes "superficial" errors in generated mods.toml dependencies keys TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8989&personal=false Index: src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt =================================================================== --- src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt (revision 54110518e8800154e80dfed876732dd925a08bd8) +++ src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt (revision 59677b86ece5864084819bbbe3c616636e9d37f8) @@ -25,6 +25,7 @@ import com.demonwav.mcdev.toml.platform.forge.ModsTomlSchema import com.demonwav.mcdev.toml.stringValue import com.demonwav.mcdev.toml.tomlType +import com.demonwav.mcdev.toml.unquoteKey import com.demonwav.mcdev.util.SemanticVersion import com.demonwav.mcdev.util.findMcpModule import com.intellij.codeInspection.InspectionManager @@ -120,7 +121,7 @@ key.segments.indexOf(keySegment) == 1 && key.segments.first().text == "dependencies" // We are visiting a dependency table ) { - val targetId = keySegment.text + val targetId = keySegment.unquoteKey() val isDeclaredId = keySegment.containingFile.children .filterIsInstance() .filter { it.header.key?.name == "mods" } Index: src/main/kotlin/toml/toml-psi.kt =================================================================== --- src/main/kotlin/toml/toml-psi.kt (revision 54110518e8800154e80dfed876732dd925a08bd8) +++ src/main/kotlin/toml/toml-psi.kt (revision 59677b86ece5864084819bbbe3c616636e9d37f8) @@ -20,21 +20,27 @@ package com.demonwav.mcdev.toml +import com.intellij.psi.PsiElement import org.toml.lang.psi.TomlElementTypes +import org.toml.lang.psi.TomlKeySegment import org.toml.lang.psi.TomlValue import org.toml.lang.psi.ext.elementType -fun TomlValue.stringValue(): String? { - val delimiter = when (firstChild?.elementType) { +private fun stringValue(element: PsiElement): String? { + val delimiter = when (element.elementType) { TomlElementTypes.BASIC_STRING -> "\"" TomlElementTypes.LITERAL_STRING -> "'" TomlElementTypes.MULTILINE_BASIC_STRING -> "\"\"\"" TomlElementTypes.MULTILINE_LITERAL_STRING -> "'''" else -> return null } - return text.removeSurrounding(delimiter) + return element.text.removeSurrounding(delimiter) } +fun TomlValue.stringValue(): String? = stringValue(firstChild) + +fun TomlKeySegment.unquoteKey(): String = stringValue(firstChild) ?: firstChild.text + val TomlValue.tomlType: TomlValueType? get() = when (firstChild?.elementType) { TomlElementTypes.BOOLEAN -> TomlValueType.BooleanType Index: src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft (revision 54110518e8800154e80dfed876732dd925a08bd8) +++ src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft (revision 59677b86ece5864084819bbbe3c616636e9d37f8) @@ -60,7 +60,7 @@ # The description text for the mod (multi line!) (#mandatory) description='''${mod_description}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${mod_id}]] #optional +[[dependencies."${mod_id}"]] #optional # the modid of the dependency modId="forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified @@ -73,7 +73,7 @@ ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT, or SERVER side="BOTH"# Here's another dependency -[[dependencies.${mod_id}]] +[[dependencies."${mod_id}"]] modId="minecraft" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version Index: src/test/kotlin/platform/forge/ModsTomlValidationInspectionTest.kt =================================================================== --- src/test/kotlin/platform/forge/ModsTomlValidationInspectionTest.kt (revision 54110518e8800154e80dfed876732dd925a08bd8) +++ src/test/kotlin/platform/forge/ModsTomlValidationInspectionTest.kt (revision 59677b86ece5864084819bbbe3c616636e9d37f8) @@ -109,4 +109,31 @@ """, ) } + + @Test + @DisplayName("Dependency For Mod With Good Placeholder") + fun dependencyForModWithGoodPlaceholder() { + val placeholder = "\${mod_id}" + doTest( + """ +[[mods]] +modId="$placeholder" +[[dependencies."$placeholder"]] + """, + ) -} + } + + @Test + @DisplayName("Dependency For Mod With Bad Placeholder") + fun dependencyForModWithBadPlaceholder() { + val goodPlaceholder = "\${mod_id}" + val badPlaceholder = "\${bad_mod_id}" + doTest( + """ +[[mods]] +modId="$goodPlaceholder" +[[dependencies."$badPlaceholder"]] + """, + ) + } +}