diff --git a/src/main/kotlin/MinecraftConfigurable.kt b/src/main/kotlin/MinecraftConfigurable.kt index 67d964ab4..49a70f57e 100644 --- a/src/main/kotlin/MinecraftConfigurable.kt +++ b/src/main/kotlin/MinecraftConfigurable.kt @@ -81,6 +81,11 @@ class MinecraftConfigurable : Configurable { row { checkBox(MCDevBundle("minecraft.settings.show_chat_color_underlines")) .bindSelected(settings::isShowChatColorUnderlines) + } + row { + checkBox(MCDevBundle("minecraft.settings.force_external_annotations")) + .bindSelected(settings::forceExternalAnnotations) + .comment(MCDevBundle("minecraft.settings.force_external_annotations.comment")) }.bottomGap(BottomGap.SMALL) group(indent = false) { diff --git a/src/main/kotlin/MinecraftSettings.kt b/src/main/kotlin/MinecraftSettings.kt index 8733f50fb..9b5ff89b4 100644 --- a/src/main/kotlin/MinecraftSettings.kt +++ b/src/main/kotlin/MinecraftSettings.kt @@ -39,6 +39,7 @@ class MinecraftSettings : PersistentStateComponent { var isShowChatColorGutterIcons: Boolean = true, var isShowChatColorUnderlines: Boolean = false, var underlineType: UnderlineType = UnderlineType.DOTTED, + var forceExternalAnnotations: Boolean = true, var mixinClassIcon: Boolean = true, @@ -108,6 +109,12 @@ class MinecraftSettings : PersistentStateComponent { state.underlineType = underlineType } + var forceExternalAnnotations: Boolean + get() = state.forceExternalAnnotations + set(forceExternalAnnotations) { + state.forceExternalAnnotations = forceExternalAnnotations + } + var mixinClassIcon: Boolean get() = state.mixinClassIcon set(mixinClassIcon) { diff --git a/src/main/kotlin/platform/mcp/McpModule.kt b/src/main/kotlin/platform/mcp/McpModule.kt index 5854ec9cf..dc0d4e3ff 100644 --- a/src/main/kotlin/platform/mcp/McpModule.kt +++ b/src/main/kotlin/platform/mcp/McpModule.kt @@ -20,6 +20,7 @@ package com.demonwav.mcdev.platform.mcp +import com.demonwav.mcdev.MinecraftSettings import com.demonwav.mcdev.facet.MinecraftFacet import com.demonwav.mcdev.platform.AbstractModule import com.demonwav.mcdev.platform.PlatformType @@ -28,6 +29,8 @@ import com.demonwav.mcdev.platform.mcp.util.McpConstants import com.demonwav.mcdev.translations.TranslationFileListener import com.demonwav.mcdev.util.runWriteTaskLater import com.intellij.json.JsonFileType +import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder +import com.intellij.openapi.externalSystem.util.ExternalSystemUtil import com.intellij.openapi.fileTypes.FileTypeManager import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager @@ -35,6 +38,8 @@ import com.intellij.psi.PsiClass import com.intellij.psi.PsiMethod import com.intellij.util.messages.MessageBusConnection import javax.swing.Icon +import org.jetbrains.plugins.gradle.settings.GradleSettings +import org.jetbrains.plugins.gradle.util.GradleConstants class McpModule(facet: MinecraftFacet) : AbstractModule(facet) { @@ -54,6 +59,21 @@ class McpModule(facet: MinecraftFacet) : AbstractModule(facet) { runWriteTaskLater { FileTypeManager.getInstance().associatePattern(JsonFileType.INSTANCE, McpConstants.PNG_MCMETA) } + + if (MinecraftSettings.instance.forceExternalAnnotations) { + // Force enable external annotations so that ours are provided + var requiresRefresh = false + for (settings in GradleSettings.getInstance(project).linkedProjectsSettings) { + if (!settings.isResolveExternalAnnotations) { + settings.isResolveExternalAnnotations = true + requiresRefresh = true + } + } + + if (requiresRefresh) { + ExternalSystemUtil.refreshProjects(ImportSpecBuilder(project, GradleConstants.SYSTEM_ID)) + } + } } private fun initSrg() { diff --git a/src/main/resources/messages/MinecraftDevelopment.properties b/src/main/resources/messages/MinecraftDevelopment.properties index 6e09278c6..92b8b129c 100644 --- a/src/main/resources/messages/MinecraftDevelopment.properties +++ b/src/main/resources/messages/MinecraftDevelopment.properties @@ -271,6 +271,8 @@ minecraft.settings.creator.repo_config.title={0} Template Repo Configuration minecraft.settings.creator.repo.default_name=My Repo minecraft.settings.creator.repo.builtin_name=Built In +minecraft.settings.force_external_annotations=Force external annotations in Minecraft projects +minecraft.settings.force_external_annotations.comment=The plugin uses external annotations to provide support for some features, like recognizing translation methods. minecraft.settings.lang_template.display_name=Localization Template minecraft.settings.lang_template.scheme=Scheme: minecraft.settings.lang_template.project_must_be_selected=You must have selected a project for this!