Skip to content

Commit

Permalink
Merge branch 'dev' into 2022.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 16, 2023
2 parents 33bd283 + 2888acf commit 24d5ad2
Show file tree
Hide file tree
Showing 51 changed files with 490 additions and 146 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin.code.style=official
ideaVersion = 2022.2
ideaVersionName = 2022.2

coreVersion = 1.6.7
coreVersion = 1.6.8
downloadIdeaSources = true

pluginTomlVersion = 222.3345.108
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Minecraft Development for IntelliJ
</tr>
</table>

Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.6.7-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.6.8-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
----------------------

<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/creator/buildsystem/gradle-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.demonwav.mcdev.creator.buildsystem

import com.demonwav.mcdev.creator.addTemplates
import com.demonwav.mcdev.creator.findStep
import com.demonwav.mcdev.creator.notifyCreatedProjectNotOpened
import com.demonwav.mcdev.creator.step.AbstractLongRunningStep
import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep
import com.demonwav.mcdev.creator.step.FixedAssetsNewProjectWizardStep
Expand Down Expand Up @@ -123,7 +124,8 @@ abstract class AbstractPatchGradleFilesStep(parent: NewProjectWizardStep) : Abst

override fun perform(project: Project) {
invokeAndWait {
if (project.isDisposed) {
if (project.isDisposed || !project.isInitialized) {
notifyCreatedProjectNotOpened()
return@invokeAndWait
}

Expand Down Expand Up @@ -195,6 +197,11 @@ open class GradleImportStep(parent: NewProjectWizardStep) : AbstractLongRunningS
open val additionalRunTasks = emptyList<String>()

override fun perform(project: Project) {
if (!project.isInitialized) {
notifyCreatedProjectNotOpened()
return
}

val rootDirectory = Path.of(context.projectFileDirectory)
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()

Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/creator/buildsystem/maven-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.demonwav.mcdev.creator.buildsystem

import com.demonwav.mcdev.creator.findStep
import com.demonwav.mcdev.creator.getVersionJson
import com.demonwav.mcdev.creator.notifyCreatedProjectNotOpened
import com.demonwav.mcdev.creator.step.AbstractLongRunningStep
import com.demonwav.mcdev.creator.step.AbstractModNameStep
import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep
Expand Down Expand Up @@ -125,7 +126,8 @@ abstract class AbstractPatchPomStep(parent: NewProjectWizardStep) : AbstractLong

override fun perform(project: Project) {
invokeAndWait {
if (project.isDisposed) {
if (project.isDisposed || !project.isInitialized) {
notifyCreatedProjectNotOpened()
return@invokeAndWait
}

Expand Down Expand Up @@ -172,7 +174,8 @@ class MavenImportStep(parent: NewProjectWizardStep) : AbstractLongRunningStep(pa
val pomFile = VfsUtil.findFile(Path.of(context.projectFileDirectory).resolve("pom.xml"), true)
?: return
val promise = invokeAndWait {
if (project.isDisposed) {
if (project.isDisposed || !project.isInitialized) {
notifyCreatedProjectNotOpened()
return@invokeAndWait null
}
MavenImportingManager.getInstance(project).linkAndImportFile(pomFile)
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/creator/creator-utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.intellij.ide.starters.local.GeneratorTemplateFile
import com.intellij.ide.wizard.AbstractNewProjectWizardStep
import com.intellij.ide.wizard.GitNewProjectWizardData
import com.intellij.ide.wizard.NewProjectWizardStep
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.openapi.observable.properties.ObservableMutableProperty
import com.intellij.openapi.observable.properties.ObservableProperty
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -149,3 +151,12 @@ fun <T> ObservableMutableProperty<T>.updateWhenChanged(dependency: ObservablePro
}

class EmptyStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep(parent)

fun notifyCreatedProjectNotOpened() {
Notification(
"Minecraft project creator",
"Created project must be opened",
"Generated files might be incomplete and the project might be broken.",
NotificationType.ERROR,
).notify(null)
}
6 changes: 6 additions & 0 deletions src/main/kotlin/creator/step/AbstractReformatFilesStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.demonwav.mcdev.creator.step

import com.demonwav.mcdev.creator.notifyCreatedProjectNotOpened
import com.intellij.codeInsight.actions.ReformatCodeProcessor
import com.intellij.ide.wizard.NewProjectWizardStep
import com.intellij.openapi.application.ReadAction
Expand Down Expand Up @@ -56,6 +57,11 @@ abstract class AbstractReformatFilesStep(parent: NewProjectWizardStep) : Abstrac

NonProjectFileWritingAccessProvider.disableChecksDuring {
WriteCommandAction.writeCommandAction(project, *files).withGlobalUndo().run<Throwable> {
if (project.isDisposed || !project.isInitialized) {
notifyCreatedProjectNotOpened()
return@run
}

ReformatCodeProcessor(project, files, null, false).run()
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/creator/step/MainClassStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class MainClassStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep
whenStepAvailable<BuildSystemPropertiesStep<*>> { buildSystemStep ->
classNameProperty.updateWhenChanged(buildSystemStep.groupIdProperty, ::suggestMainClassName)
classNameProperty.updateWhenChanged(buildSystemStep.artifactIdProperty, ::suggestMainClassName)

buildSystemStep.groupIdProperty.updateWhenChanged(classNameProperty, ::suggestGroupId)
}
whenStepAvailable<AbstractModNameStep> { modNameStep ->
classNameProperty.updateWhenChanged(modNameStep.nameProperty, ::suggestMainClassName)
Expand Down
104 changes: 104 additions & 0 deletions src/main/kotlin/creator/step/ModIdStep.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2023 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.creator.step

import com.demonwav.mcdev.creator.storeToData
import com.intellij.ide.wizard.AbstractNewProjectWizardStep
import com.intellij.ide.wizard.NewProjectWizardBaseData
import com.intellij.ide.wizard.NewProjectWizardStep
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.validation.AFTER_GRAPH_PROPAGATION
import com.intellij.openapi.ui.validation.CHECK_NON_EMPTY
import com.intellij.openapi.ui.validation.and
import com.intellij.openapi.ui.validation.validationErrorIf
import com.intellij.openapi.util.Key
import com.intellij.ui.dsl.builder.COLUMNS_MEDIUM
import com.intellij.ui.dsl.builder.Panel
import com.intellij.ui.dsl.builder.bindText
import com.intellij.ui.dsl.builder.columns
import com.intellij.ui.dsl.builder.textValidation

private val validModIdRegex = "[a-z][a-z0-9-_]{1,63}".toRegex()
private val invalidModIdRegex = "[^a-z0-9-_]+".toRegex()

private val validForgeModIdRegex = "[a-z][a-z0-9_]{1,63}".toRegex()
private val invalidForgeModIdRegex = "[^a-z0-9_]+".toRegex()

abstract class AbstractModIdStep(
parent: NewProjectWizardStep,
private val validRegex: Regex = validModIdRegex,
private val invalidRegex: Regex = invalidModIdRegex
) : AbstractNewProjectWizardStep(parent) {
private val baseData = data.getUserData(NewProjectWizardBaseData.KEY)
?: throw IllegalStateException("Mod id step created without base step")
val idProperty = propertyGraph.lazyProperty(::suggestId)
var id by idProperty

private val idValidation = validationErrorIf<String>("Id must match $validRegex") { !it.matches(validRegex) }

init {
idProperty.dependsOn(baseData.nameProperty, ::suggestId)
storeToData()
}

fun suggestId(): String {
val sanitized = baseData.name.lowercase().replace(invalidRegex, "_")
if (sanitized.length > 64) {
return sanitized.substring(0, 64)
}
return sanitized
}

abstract val label: String

override fun setupUI(builder: Panel) {
with(builder) {
row(label) {
textField()
.bindText(idProperty)
.columns(COLUMNS_MEDIUM)
.validationRequestor(AFTER_GRAPH_PROPAGATION(propertyGraph))
.textValidation(CHECK_NON_EMPTY and idValidation)
}
}
}

override fun setupProject(project: Project) {
data.putUserData(KEY, id)
}

companion object {
val KEY = Key.create<String>("${AbstractModIdStep::class.java.name}.id")
}
}

class ModIdStep(parent: NewProjectWizardStep) : AbstractModIdStep(parent) {
override val label = "Mod Id:"
}

class ForgeStyleModIdStep(parent: NewProjectWizardStep) :
AbstractModIdStep(parent, validForgeModIdRegex, invalidForgeModIdRegex) {
override val label = "Mod Id:"
}

class PluginIdStep(parent: NewProjectWizardStep) : AbstractModIdStep(parent) {
override val label = "Plugin Id:"
}
10 changes: 6 additions & 4 deletions src/main/kotlin/insight/ListenerEventAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.demonwav.mcdev.insight

import com.demonwav.mcdev.MinecraftSettings
import com.demonwav.mcdev.facet.MinecraftFacet
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
Expand Down Expand Up @@ -53,10 +54,11 @@ class ListenerEventAnnotator : Annotator {
return
}

val method: UMethod = element.toUElement()?.uastParent as? UMethod
?: element.getUastParentOfType<UTypeReferenceExpression>()
?.getParentOfType<UParameter>()?.uastParent as? UMethod // Be sure to be on the type of a parameter
?: return
val method: UMethod = runCatchingKtIdeaExceptions {
element.toUElement()?.uastParent as? UMethod
?: element.getUastParentOfType<UTypeReferenceExpression>()
?.getParentOfType<UParameter>()?.uastParent as? UMethod // Be sure to be on the type of a parameter
} ?: return
if (method.javaPsi.hasModifierProperty(PsiModifier.ABSTRACT)) {
// I don't think any implementation allows for abstract
return
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/insight/ListenerLineMarkerProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class ListenerLineMarkerProvider : LineMarkerProviderDescriptor() {
return GutterIconNavigationHandler handler@{ _, element ->
val (eventClass, _) = element.toUElementOfType<UIdentifier>()?.uastEventListener ?: return@handler
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.declaration")
eventClass.navigate(true)
if (eventClass.canNavigate()) {
eventClass.navigate(true)
}
}
}

Expand Down
20 changes: 19 additions & 1 deletion src/main/kotlin/nbt/editor/NbtFileEditorProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.ui.EditorNotifications
import com.intellij.ui.components.JBLoadingPanel
import com.intellij.util.IncorrectOperationException
import java.awt.BorderLayout
Expand Down Expand Up @@ -92,6 +93,7 @@ private class NbtFileEditor(
private var editor: FileEditor? = null
private val editorCheckedDisposable = Disposer.newCheckedDisposable()
private val component = JPanel(BorderLayout())
private val tempUserData = mutableMapOf<Any?, Any?>()

init {
val loading = JBLoadingPanel(null, this)
Expand Down Expand Up @@ -123,10 +125,16 @@ private class NbtFileEditor(
Disposer.dispose(this)
return@let
}
tempUserData.forEach { (k, v) ->
@Suppress("UNCHECKED_CAST")
editor.putUserData(k as Key<Any>, v)
}
tempUserData.clear()
invokeLater {
component.add(toolbar.panel, BorderLayout.NORTH)
component.add(editor.component, BorderLayout.CENTER)
}
EditorNotifications.getInstance(project).updateAllNotifications()
}

// This can be null if the file is too big to be parsed as a psi file
Expand Down Expand Up @@ -178,12 +186,22 @@ private class NbtFileEditor(

override fun getComponent() = component
override fun getPreferredFocusedComponent() = editor.exec { preferredFocusedComponent }
override fun <T : Any?> getUserData(key: Key<T>) = editor.exec { getUserData(key) }
override fun <T : Any?> getUserData(key: Key<T>): T? {
if (editor == null) {
@Suppress("UNCHECKED_CAST")
return tempUserData[key] as? T
}
return editor.exec { getUserData(key) }
}
override fun selectNotify() {
editor.exec { selectNotify() }
}

override fun <T : Any?> putUserData(key: Key<T>, value: T?) {
if (editor == null) {
tempUserData[key] = value
return
}
editor.exec { putUserData(key, value) }
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/kotlin/platform/architectury/creator/asset-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep
import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport
import com.demonwav.mcdev.creator.findStep
import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep
import com.demonwav.mcdev.creator.step.AbstractModIdStep
import com.demonwav.mcdev.creator.step.AbstractModNameStep
import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep
import com.demonwav.mcdev.creator.step.AuthorsStep
Expand Down Expand Up @@ -74,7 +75,8 @@ class ArchitecturyProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongR
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()
val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false
val javaVersion = findStep<JdkProjectSetupFinalizer>().preferredJdk.ordinal
val packageName = "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}"
val modId = data.getUserData(AbstractModIdStep.KEY) ?: return
val packageName = "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}"
val mcVersion = data.getUserData(ArchitecturyVersionChainStep.MC_VERSION_KEY) ?: return
val modName = data.getUserData(AbstractModNameStep.KEY) ?: return
val forgeVersion = data.getUserData(ArchitecturyVersionChainStep.FORGE_VERSION_KEY) ?: return
Expand Down Expand Up @@ -114,6 +116,7 @@ class ArchitecturyProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongR
"PACK_COMMENT" to packDescriptor.comment,
"PACKAGE_NAME" to packageName,
"JAVA_VERSION" to javaVersion,
"MOD_ID" to modId,
"MOD_NAME" to modName,
"DISPLAY_TEST" to hasDisplayTestInManifest,
"FORGE_SPEC_VERSION" to forgeVersion.parts[0].versionString,
Expand Down Expand Up @@ -160,9 +163,9 @@ class ArchitecturyProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongR
assets.addTemplateProperties(
"MIXINS" to "true",
)
val commonMixinsFile = "common/src/main/resources/${buildSystemProps.artifactId}-common.mixins.json"
val forgeMixinsFile = "forge/src/main/resources/${buildSystemProps.artifactId}.mixins.json"
val fabricMixinsFile = "fabric/src/main/resources/${buildSystemProps.artifactId}.mixins.json"
val commonMixinsFile = "common/src/main/resources/$modId-common.mixins.json"
val forgeMixinsFile = "forge/src/main/resources/$modId.mixins.json"
val fabricMixinsFile = "fabric/src/main/resources/$modId.mixins.json"
assets.addTemplates(
project,
commonMixinsFile to MinecraftTemplates.ARCHITECTURY_COMMON_MIXINS_JSON_TEMPLATE,
Expand Down Expand Up @@ -194,6 +197,7 @@ abstract class ArchitecturyMainClassStep(

override fun setupAssets(project: Project) {
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()
val modId = data.getUserData(AbstractModIdStep.KEY) ?: return
val modName = data.getUserData(AbstractModNameStep.KEY) ?: return
val useArchApi = data.getUserData(ArchitecturyVersionChainStep.ARCHITECTURY_API_VERSION_KEY) != null

Expand All @@ -203,6 +207,7 @@ abstract class ArchitecturyMainClassStep(
"PACKAGE_NAME" to packageName,
"CLASS_NAME" to className,
"ARTIFACT_ID" to buildSystemProps.artifactId,
"MOD_ID" to modId,
"MOD_NAME" to modName,
"MOD_VERSION" to buildSystemProps.version,
"ARCHITECTURY_PACKAGE" to architecturyPackage,
Expand Down
Loading

0 comments on commit 24d5ad2

Please sign in to comment.