Skip to content

Commit

Permalink
Provide different descriptions for MixinConfigFileTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Sep 28, 2024
1 parent 3370b42 commit 3c82c6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
9 changes: 2 additions & 7 deletions src/main/kotlin/platform/mixin/MixinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import com.demonwav.mcdev.facet.MinecraftFacetDetector
import com.demonwav.mcdev.platform.AbstractModule
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.platform.mixin.config.MixinConfig
import com.demonwav.mcdev.platform.mixin.config.MixinConfigFileType
import com.demonwav.mcdev.platform.mixin.framework.MIXIN_LIBRARY_KIND
import com.demonwav.mcdev.util.SemanticVersion
import com.demonwav.mcdev.util.nullable
import com.intellij.json.psi.JsonFile
import com.intellij.json.psi.JsonObject
import com.intellij.openapi.fileTypes.FileTypeManager
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClass
Expand All @@ -53,12 +53,7 @@ class MixinModule(facet: MinecraftFacet) : AbstractModule(facet) {
override val icon: Icon? = null

companion object {
private val mixinFileTypes by lazy {
listOfNotNull(
FileTypeManager.getInstance().findFileTypeByName("Mixin Json Configuration"),
FileTypeManager.getInstance().findFileTypeByName("Mixin Json5 Configuration")
)
}
private val mixinFileTypes = listOf(MixinConfigFileType.Json, MixinConfigFileType.Json5)

fun getMixinConfigs(
project: Project,
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/platform/mixin/config/MixinConfigFileType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@ import com.intellij.openapi.fileTypes.ex.FileTypeIdentifiableByVirtualFile
import com.intellij.openapi.vfs.VirtualFile

interface MixinConfigFileType : FileTypeIdentifiableByVirtualFile {
fun getFilenameRegex() : Regex
fun getFilenameRegex(): Regex

// Dynamic file type detection is sadly needed as we're overriding the built-in json file type.
// Simply using an extension pattern is not sufficient as there is no way to bump the version to tell
// the cache that the pattern has changed, as it now has, without changing the file type name.
// See https://www.plugin-dev.com/intellij/custom-language/file-type-detection/#guidelines
override fun isMyFileType(file: VirtualFile) = file.name.contains(getFilenameRegex())

override fun getDescription() = "Mixin configuration"
override fun getDefaultExtension() = ""
override fun getIcon() = PlatformAssets.MIXIN_ICON

object Json : LanguageFileType(JsonLanguage.INSTANCE), MixinConfigFileType {
private val filenameRegex = "(^|\\.)mixins?(\\.[^.]+)*\\.json\$".toRegex()

override fun getFilenameRegex() : Regex = filenameRegex
override fun getFilenameRegex(): Regex = filenameRegex
override fun getName() = "Mixin Json Configuration"
override fun getDescription() = "Mixin Json configuration"
}

object Json5 : LanguageFileType(Json5Language.INSTANCE), MixinConfigFileType {
private var filenameRegex = "(^|\\.)mixins?(\\.[^.]+)*\\.json5\$".toRegex()

override fun getFilenameRegex() : Regex = filenameRegex
override fun getFilenameRegex(): Regex = filenameRegex
override fun getName() = "Mixin Json5 Configuration"
override fun getDescription() = "Mixin Json5 configuration"
}
}
}

0 comments on commit 3c82c6b

Please sign in to comment.