From 32dfbc92e0d5687c907b36a25024131100497155 Mon Sep 17 00:00:00 2001 From: Arham4 <arhamjsiddiqui@gmail.com> Date: Sun, 22 Oct 2023 19:56:36 -0400 Subject: [PATCH] Add more descriptive error messages --- .../shanty/intellij/mod/ModFileExtension.kt | 46 +++++++++---------- .../inspections/fix/CreateModFileQuickFix.kt | 8 +--- .../mod/inspections/visitor/EnumVisitor.kt | 4 +- .../mod/inspections/visitor/StructVisitor.kt | 11 +++-- .../resources/messages/ModBundle.properties | 4 +- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/ps/shanty/intellij/mod/ModFileExtension.kt b/src/main/kotlin/ps/shanty/intellij/mod/ModFileExtension.kt index 5cacd60..9d6c1c8 100644 --- a/src/main/kotlin/ps/shanty/intellij/mod/ModFileExtension.kt +++ b/src/main/kotlin/ps/shanty/intellij/mod/ModFileExtension.kt @@ -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"), ; diff --git a/src/main/kotlin/ps/shanty/intellij/mod/inspections/fix/CreateModFileQuickFix.kt b/src/main/kotlin/ps/shanty/intellij/mod/inspections/fix/CreateModFileQuickFix.kt index d34a21c..bbb52f5 100644 --- a/src/main/kotlin/ps/shanty/intellij/mod/inspections/fix/CreateModFileQuickFix.kt +++ b/src/main/kotlin/ps/shanty/intellij/mod/inspections/fix/CreateModFileQuickFix.kt @@ -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 @@ -14,15 +12,11 @@ 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, @@ -30,7 +24,7 @@ class CreateModFileQuickFix( 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) { diff --git a/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/EnumVisitor.kt b/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/EnumVisitor.kt index 55e57a7..e8881db 100644 --- a/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/EnumVisitor.kt +++ b/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/EnumVisitor.kt @@ -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) ) @@ -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) ) diff --git a/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/StructVisitor.kt b/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/StructVisitor.kt index 8a52f56..1b5ff24 100644 --- a/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/StructVisitor.kt +++ b/src/main/kotlin/ps/shanty/intellij/mod/inspections/visitor/StructVisitor.kt @@ -24,20 +24,21 @@ 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) { @@ -45,7 +46,7 @@ class StructVisitor(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, extension.extension, extension.sntName), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, CreateModFileQuickFix(extension.extension, valueText, smartFolder) ) diff --git a/src/main/resources/messages/ModBundle.properties b/src/main/resources/messages/ModBundle.properties index 22fd5c4..cf4da5c 100644 --- a/src/main/resources/messages/ModBundle.properties +++ b/src/main/resources/messages/ModBundle.properties @@ -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} \ No newline at end of file