|
| 1 | +/* |
| 2 | + * Minecraft Development for IntelliJ |
| 3 | + * |
| 4 | + * https://mcdev.io/ |
| 5 | + * |
| 6 | + * Copyright (C) 2024 minecraft-dev |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published |
| 10 | + * by the Free Software Foundation, version 3.0 only. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.demonwav.mcdev.platform.mcp.aw.format |
| 22 | + |
| 23 | +import com.demonwav.mcdev.platform.mcp.aw.AwLanguage |
| 24 | +import com.intellij.application.options.CodeStyleAbstractConfigurable |
| 25 | +import com.intellij.application.options.CodeStyleAbstractPanel |
| 26 | +import com.intellij.application.options.TabbedLanguageCodeStylePanel |
| 27 | +import com.intellij.lang.Language |
| 28 | +import com.intellij.openapi.util.NlsContexts |
| 29 | +import com.intellij.psi.codeStyle.CodeStyleConfigurable |
| 30 | +import com.intellij.psi.codeStyle.CodeStyleSettings |
| 31 | +import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable |
| 32 | +import com.intellij.psi.codeStyle.CodeStyleSettingsProvider |
| 33 | +import com.intellij.psi.codeStyle.CustomCodeStyleSettings |
| 34 | +import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider |
| 35 | + |
| 36 | +class AwCodeStyleSettings(val settings: CodeStyleSettings) : CustomCodeStyleSettings("AwCodeStyleSettings", settings) { |
| 37 | + @JvmField |
| 38 | + var SPACE_BEFORE_ENTRY_COMMENT = true |
| 39 | + |
| 40 | + @JvmField |
| 41 | + var ALIGN_ENTRY_CLASS_AND_MEMBER = true |
| 42 | +} |
| 43 | + |
| 44 | +class AwCodeStyleSettingsProvider : CodeStyleSettingsProvider() { |
| 45 | + override fun createCustomSettings(settings: CodeStyleSettings): CustomCodeStyleSettings = |
| 46 | + AwCodeStyleSettings(settings) |
| 47 | + |
| 48 | + override fun getConfigurableDisplayName(): @NlsContexts.ConfigurableName String? = AwLanguage.displayName |
| 49 | + |
| 50 | + override fun createConfigurable( |
| 51 | + settings: CodeStyleSettings, |
| 52 | + modelSettings: CodeStyleSettings |
| 53 | + ): CodeStyleConfigurable { |
| 54 | + return object : CodeStyleAbstractConfigurable(settings, modelSettings, configurableDisplayName) { |
| 55 | + override fun createPanel(settings: CodeStyleSettings): CodeStyleAbstractPanel { |
| 56 | + return AwCodeStyleSettingsConfigurable(currentSettings, settings) |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +class AwCodeStyleSettingsConfigurable(currentSettings: CodeStyleSettings, settings: CodeStyleSettings) : |
| 63 | + TabbedLanguageCodeStylePanel(AwLanguage, currentSettings, settings) |
| 64 | + |
| 65 | +class AwLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvider() { |
| 66 | + |
| 67 | + override fun getLanguage(): Language = AwLanguage |
| 68 | + |
| 69 | + override fun customizeSettings(consumer: CodeStyleSettingsCustomizable, settingsType: SettingsType) { |
| 70 | + if (settingsType == SettingsType.SPACING_SETTINGS) { |
| 71 | + consumer.showCustomOption( |
| 72 | + AwCodeStyleSettings::class.java, |
| 73 | + "SPACE_BEFORE_ENTRY_COMMENT", |
| 74 | + "Space before entry comment", |
| 75 | + "Spacing and alignment" |
| 76 | + ) |
| 77 | + consumer.showCustomOption( |
| 78 | + AwCodeStyleSettings::class.java, |
| 79 | + "ALIGN_ENTRY_CLASS_AND_MEMBER", |
| 80 | + "Align entry class name and member", |
| 81 | + "Spacing and alignment" |
| 82 | + ) |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + override fun getCodeSample(settingsType: SettingsType): String? = """ |
| 87 | + # Some header comment |
| 88 | +
|
| 89 | + accessible method net/minecraft/client/Minecraft pickBlock ()V # This is an entry comment |
| 90 | + accessible method net/minecraft/client/Minecraft userProperties ()Lcom/mojang/authlib/minecraft/UserApiService${'$'}UserProperties; |
| 91 | +
|
| 92 | + # Each group can be aligned independently |
| 93 | + accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen clickedSlot I |
| 94 | + accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen playerInventoryTitle Ljava/lang/String; |
| 95 | + extendable method net/minecraft/client/gui/screens/inventory/AbstractContainerScreen findSlot (DD)Lnet/minecraft/world/inventory/Slot; |
| 96 | + """.trimIndent() |
| 97 | +} |
0 commit comments