Skip to content

Commit

Permalink
Fix #2408 Force external annotations by default
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Dec 3, 2024
1 parent 28ca789 commit 092f5c1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/MinecraftConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/MinecraftSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
var isShowChatColorGutterIcons: Boolean = true,
var isShowChatColorUnderlines: Boolean = false,
var underlineType: UnderlineType = UnderlineType.DOTTED,
var forceExternalAnnotations: Boolean = true,

var mixinClassIcon: Boolean = true,

Expand Down Expand Up @@ -108,6 +109,12 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
state.underlineType = underlineType
}

var forceExternalAnnotations: Boolean
get() = state.forceExternalAnnotations
set(forceExternalAnnotations) {
state.forceExternalAnnotations = forceExternalAnnotations
}

var mixinClassIcon: Boolean
get() = state.mixinClassIcon
set(mixinClassIcon) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/platform/mcp/McpModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,13 +29,17 @@ 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
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) {

Expand All @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages/MinecraftDevelopment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 092f5c1

Please sign in to comment.