Skip to content

Commit

Permalink
Make mods.toml support work with neoforge.mods.toml too
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Aug 1, 2024
1 parent 1801be0 commit d74d95e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ object NeoForgeConstants {
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"
}
29 changes: 29 additions & 0 deletions src/main/kotlin/toml/platform/forge/ForgeTomlConstants.kt
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,7 +106,7 @@ class ModsTomlDocumentationProvider : DocumentationProvider {
}

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.demonwav.mcdev.toml.platform.forge.inspections

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
Expand Down Expand Up @@ -53,14 +54,14 @@ class ModsTomlValidationInspection : LocalInspectionTool() {
override fun getStaticDescription(): String = "Checks mods.toml files for errors"

override fun processFile(file: PsiFile, manager: InspectionManager): MutableList<ProblemDescriptor> {
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
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/toml/toml-patterns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +34,8 @@ import org.toml.lang.psi.TomlTableHeader
inline fun <reified E : PsiElement> inModsToml(): PsiElementPattern.Capture<E> = inModsToml(E::class.java)

fun <E : PsiElement> inModsToml(clazz: Class<E>): PsiElementPattern.Capture<E> =
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<PsiElement> =
inModsToml<PsiElement>().withParent(TomlKeySegment::class.java)
Expand Down

0 comments on commit d74d95e

Please sign in to comment.