Skip to content

Commit

Permalink
Add more descriptive error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Arham4 committed Oct 22, 2023
1 parent 0e8b1c0 commit 32dfbc9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
46 changes: 22 additions & 24 deletions src/main/kotlin/ps/shanty/intellij/mod/ModFileExtension.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package ps.shanty.intellij.mod

enum class ModFileExtension(val extension: String, val patchFolder: String, val type: String) {
MOD("mod", "", ""),
BAS(extension = "bas", patchFolder = "bas", type = ""),
ENUM(extension = "enum", patchFolder = "enum", type = "enum"),
HUNT(extension = "hunt", patchFolder = "hunt", type = ""),
INV(extension = "inv", patchFolder = "inv", type = "inv"),
LOC(extension = "loc", patchFolder = "loc", type = "loc"),
MAPAREA(extension = "maparea", patchFolder = "map_area", type = "map_area"),
MAPLABEL(extension = "maplabel", patchFolder = "map_label", type = ""),
MAPFUNC(extension = "mapfunc", patchFolder = "mapfunction", type = ""),
NPC(extension = "npc", patchFolder = "npc", type = "npc"),
NS(extension = "ns", patchFolder = "npcspawn", type = ""),
OBJ(extension = "obj", patchFolder = "obj", type = "named_obj"),
PARAM(extension = "param", patchFolder = "param", type = "param"),
SEQ(extension = "seq", patchFolder = "seq", type = "seq"),
STRUCT(extension = "struct", patchFolder = "struct", type = "struct"),
VARBIT(extension = "varbit", patchFolder = "varbit", type = "varbit"),
VARCLAN(extension = "varclan", patchFolder = "varclan", type = ""),
VARCLANSETTING(extension = "varclansetting", patchFolder = "varclansetting", type = ""),
VARCLIENT(extension = "varclient", patchFolder = "varclient", type = ""),
VARDOUBLE(extension = "vardouble", patchFolder = "vardouble", type = ""),
VARLONG(extension = "varlong", patchFolder = "varlong", type = ""),
VARP(extension = "varp", patchFolder = "varp", type = "varp"),
VARSTRING(extension = "varstring", patchFolder = "varstring", type = ""),
enum class ModFileExtension(val extension: String, val patchFolder: String, val type: String, val sntName: String) {
MOD("mod", "", "", ""),
BAS(extension = "bas", patchFolder = "bas", type = "", sntName = "bas"),
ENUM(extension = "enum", patchFolder = "enum", type = "enum", sntName = "enum"),
HUNT(extension = "hunt", patchFolder = "hunt", type = "", sntName = "hunt"),
INV(extension = "inv", patchFolder = "inv", type = "inv", sntName = "inv"),
LOC(extension = "loc", patchFolder = "loc", type = "loc", sntName = "loc"),
MAPAREA(extension = "maparea", patchFolder = "map_area", type = "map_area", sntName = "map_area"),
MAPLABEL(extension = "maplabel", patchFolder = "map_label", type = "", sntName = "mapfunction"),
MAPFUNC(extension = "mapfunc", patchFolder = "mapfunction", type = "", sntName = "mapfunction"),
NPC(extension = "npc", patchFolder = "npc", type = "npc", sntName = "npc"),
NS(extension = "ns", patchFolder = "npcspawn", type = "", sntName = ""),
OBJ(extension = "obj", patchFolder = "obj", type = "named_obj", sntName = "obj"),
PARAM(extension = "param", patchFolder = "param", type = "param", sntName = "param"),
SEQ(extension = "seq", patchFolder = "seq", type = "seq", sntName = "seq"),
STRUCT(extension = "struct", patchFolder = "struct", type = "struct", sntName = "struct"),
VARBIT(extension = "varbit", patchFolder = "varbit", type = "varbit", sntName = "varbit"),
VARCLIENT(extension = "varclient", patchFolder = "varclient", type = "", sntName = "varclient"),
VARDOUBLE(extension = "vardouble", patchFolder = "vardouble", type = "", sntName = "vardouble"),
VARLONG(extension = "varlong", patchFolder = "varlong", type = "", sntName = "varlong"),
VARP(extension = "varp", patchFolder = "varp", type = "varp", sntName = "varp"),
VARSTRING(extension = "varstring", patchFolder = "varstring", type = "", sntName = "varstring"),

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.intellij.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.fileChooser.FileSystemTreeFactory
import com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.project.Project
Expand All @@ -14,23 +12,19 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiFileFactory
import com.intellij.psi.SmartPsiElementPointer
import com.intellij.ui.DirtyUI
import org.jetbrains.annotations.Nls
import ps.shanty.intellij.PluginIcons
import ps.shanty.intellij.mod.ModBundle
import ps.shanty.intellij.mod.ModFileExtension
import ps.shanty.intellij.mod.ModFileType
import ps.shanty.intellij.mod.ModLanguage
import ps.shanty.intellij.mod.inspections.validator.CreateModFileHandler
import ps.shanty.intellij.mod.util.ModUtil.findPatchFolder

class CreateModFileQuickFix(
private val type: String,
private val configName: String,
private val folder: SmartPsiElementPointer<PsiDirectory>,
) : LocalQuickFix {
override fun getFamilyName(): @Nls String {
return ModBundle.message("ModInvalidGameCacheConfigInspection.create.file.quickfix.name")
return ModBundle.message("ModInvalidGameCacheConfigInspection.create.file.quickfix.name", configName, type)
}

override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EnumVisitor(private val holder: ProblemsHolder) : YamlPsiElementVisitor()
val smartFolder = SmartPointerManager.getInstance(mapping.project).createSmartPsiElementPointer(folder)
holder.registerProblem(
keyValue.key!!,
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", keyText),
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", keyText, keyExtension.extension, keyExtension.sntName),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
CreateModFileQuickFix(keyExtension.extension, keyText, smartFolder)
)
Expand All @@ -48,7 +48,7 @@ class EnumVisitor(private val holder: ProblemsHolder) : YamlPsiElementVisitor()
val smartFolder = SmartPointerManager.getInstance(mapping.project).createSmartPsiElementPointer(folder)
holder.registerProblem(
keyValue.value!!,
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", valueText),
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", valueText, valueExtension.extension, valueExtension.sntName),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
CreateModFileQuickFix(valueExtension.extension, valueText, smartFolder)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,29 @@ class StructVisitor(private val holder: ProblemsHolder) : YamlPsiElementVisitor(
}

for (keyValue in params.keyValues) {
val keyEntries = SNTKeyIndex.instance.get(keyValue.keyText, mapping.project, GlobalSearchScope.allScope(mapping.project))
val keyText = keyValue.key?.text?.replace("\"", "") ?: continue
val keyEntries = SNTKeyIndex.instance.get(keyText, mapping.project, GlobalSearchScope.allScope(mapping.project))

if (keyEntries.isEmpty()) {
val folder = findPatchFolder(mapping.project, ModFileExtension.PARAM.patchFolder)
val smartFolder = SmartPointerManager.getInstance(mapping.project).createSmartPsiElementPointer(folder)
holder.registerProblem(
keyValue.key!!,
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", keyValue.keyText),
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", keyText, ModFileExtension.PARAM.extension, ModFileExtension.PARAM.sntName),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
CreateModFileQuickFix(ModFileExtension.PARAM.extension, keyValue.keyText, smartFolder)
CreateModFileQuickFix(ModFileExtension.PARAM.extension, keyText, smartFolder)
)
}

val extension = ParamUtil.findParamType(mapping.project, keyValue.keyText) ?: continue
val extension = ParamUtil.findParamType(mapping.project, keyText) ?: continue
val valueText = keyValue.value?.text?.replace("\"", "") ?: continue
val valueEntries = SNTKeyIndex.instance.get(valueText, mapping.project, GlobalSearchScope.allScope(mapping.project))
if (valueEntries.isEmpty() && keyValue.value != null) {
val folder = findPatchFolder(mapping.project, extension.patchFolder)
val smartFolder = SmartPointerManager.getInstance(mapping.project).createSmartPsiElementPointer(folder)
holder.registerProblem(
keyValue.value!!,
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", valueText),
ModBundle.message("ModInvalidGameCacheConfigInspection.no.snt.entry", valueText, extension.extension, extension.sntName),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
CreateModFileQuickFix(extension.extension, valueText, smartFolder)
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/messages/ModBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inspections.invalid.game.cache.config=Invalid game cache config
ModDuplicatedKeysInspection.duplicated.key=Key ''{0}'' is duplicated
ModDuplicatedKeysInspection.remove.key.quickfix.name=Remove key
ModInvalidGameCacheConfigInspection.no.snt.entry=No SNT entry exists for ''{0}''
ModInvalidGameCacheConfigInspection.create.file.quickfix.name=Create config file
ModInvalidGameCacheConfigInspection.no.snt.entry=No SNT entry exists for ''{0}'' in {2}.snt.\n\nCreate {0}.{1} to resolve it, then patch the cache.
ModInvalidGameCacheConfigInspection.create.file.quickfix.name=Create {0}.{1}
progress.creating.mod.file=Creating Mod file {1}

0 comments on commit 32dfbc9

Please sign in to comment.