Skip to content

Commit 24d5ad2

Browse files
committed
Merge branch 'dev' into 2022.2
2 parents 33bd283 + 2888acf commit 24d5ad2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+490
-146
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ kotlin.code.style=official
2424
ideaVersion = 2022.2
2525
ideaVersionName = 2022.2
2626

27-
coreVersion = 1.6.7
27+
coreVersion = 1.6.8
2828
downloadIdeaSources = true
2929

3030
pluginTomlVersion = 222.3345.108

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Minecraft Development for IntelliJ
3535
</tr>
3636
</table>
3737

38-
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)
38+
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)
3939
----------------------
4040

4141
<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>

src/main/kotlin/creator/buildsystem/gradle-steps.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package com.demonwav.mcdev.creator.buildsystem
2222

2323
import com.demonwav.mcdev.creator.addTemplates
2424
import com.demonwav.mcdev.creator.findStep
25+
import com.demonwav.mcdev.creator.notifyCreatedProjectNotOpened
2526
import com.demonwav.mcdev.creator.step.AbstractLongRunningStep
2627
import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep
2728
import com.demonwav.mcdev.creator.step.FixedAssetsNewProjectWizardStep
@@ -123,7 +124,8 @@ abstract class AbstractPatchGradleFilesStep(parent: NewProjectWizardStep) : Abst
123124

124125
override fun perform(project: Project) {
125126
invokeAndWait {
126-
if (project.isDisposed) {
127+
if (project.isDisposed || !project.isInitialized) {
128+
notifyCreatedProjectNotOpened()
127129
return@invokeAndWait
128130
}
129131

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

197199
override fun perform(project: Project) {
200+
if (!project.isInitialized) {
201+
notifyCreatedProjectNotOpened()
202+
return
203+
}
204+
198205
val rootDirectory = Path.of(context.projectFileDirectory)
199206
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()
200207

src/main/kotlin/creator/buildsystem/maven-steps.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package com.demonwav.mcdev.creator.buildsystem
2222

2323
import com.demonwav.mcdev.creator.findStep
2424
import com.demonwav.mcdev.creator.getVersionJson
25+
import com.demonwav.mcdev.creator.notifyCreatedProjectNotOpened
2526
import com.demonwav.mcdev.creator.step.AbstractLongRunningStep
2627
import com.demonwav.mcdev.creator.step.AbstractModNameStep
2728
import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep
@@ -125,7 +126,8 @@ abstract class AbstractPatchPomStep(parent: NewProjectWizardStep) : AbstractLong
125126

126127
override fun perform(project: Project) {
127128
invokeAndWait {
128-
if (project.isDisposed) {
129+
if (project.isDisposed || !project.isInitialized) {
130+
notifyCreatedProjectNotOpened()
129131
return@invokeAndWait
130132
}
131133

@@ -172,7 +174,8 @@ class MavenImportStep(parent: NewProjectWizardStep) : AbstractLongRunningStep(pa
172174
val pomFile = VfsUtil.findFile(Path.of(context.projectFileDirectory).resolve("pom.xml"), true)
173175
?: return
174176
val promise = invokeAndWait {
175-
if (project.isDisposed) {
177+
if (project.isDisposed || !project.isInitialized) {
178+
notifyCreatedProjectNotOpened()
176179
return@invokeAndWait null
177180
}
178181
MavenImportingManager.getInstance(project).linkAndImportFile(pomFile)

src/main/kotlin/creator/creator-utils.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import com.intellij.ide.starters.local.GeneratorTemplateFile
2929
import com.intellij.ide.wizard.AbstractNewProjectWizardStep
3030
import com.intellij.ide.wizard.GitNewProjectWizardData
3131
import com.intellij.ide.wizard.NewProjectWizardStep
32+
import com.intellij.notification.Notification
33+
import com.intellij.notification.NotificationType
3234
import com.intellij.openapi.observable.properties.ObservableMutableProperty
3335
import com.intellij.openapi.observable.properties.ObservableProperty
3436
import com.intellij.openapi.project.Project
@@ -149,3 +151,12 @@ fun <T> ObservableMutableProperty<T>.updateWhenChanged(dependency: ObservablePro
149151
}
150152

151153
class EmptyStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep(parent)
154+
155+
fun notifyCreatedProjectNotOpened() {
156+
Notification(
157+
"Minecraft project creator",
158+
"Created project must be opened",
159+
"Generated files might be incomplete and the project might be broken.",
160+
NotificationType.ERROR,
161+
).notify(null)
162+
}

src/main/kotlin/creator/step/AbstractReformatFilesStep.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.demonwav.mcdev.creator.step
2222

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

5758
NonProjectFileWritingAccessProvider.disableChecksDuring {
5859
WriteCommandAction.writeCommandAction(project, *files).withGlobalUndo().run<Throwable> {
60+
if (project.isDisposed || !project.isInitialized) {
61+
notifyCreatedProjectNotOpened()
62+
return@run
63+
}
64+
5965
ReformatCodeProcessor(project, files, null, false).run()
6066
}
6167
}

src/main/kotlin/creator/step/MainClassStep.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class MainClassStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep
6464
whenStepAvailable<BuildSystemPropertiesStep<*>> { buildSystemStep ->
6565
classNameProperty.updateWhenChanged(buildSystemStep.groupIdProperty, ::suggestMainClassName)
6666
classNameProperty.updateWhenChanged(buildSystemStep.artifactIdProperty, ::suggestMainClassName)
67-
68-
buildSystemStep.groupIdProperty.updateWhenChanged(classNameProperty, ::suggestGroupId)
6967
}
7068
whenStepAvailable<AbstractModNameStep> { modNameStep ->
7169
classNameProperty.updateWhenChanged(modNameStep.nameProperty, ::suggestMainClassName)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2023 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.creator.step
22+
23+
import com.demonwav.mcdev.creator.storeToData
24+
import com.intellij.ide.wizard.AbstractNewProjectWizardStep
25+
import com.intellij.ide.wizard.NewProjectWizardBaseData
26+
import com.intellij.ide.wizard.NewProjectWizardStep
27+
import com.intellij.openapi.project.Project
28+
import com.intellij.openapi.ui.validation.AFTER_GRAPH_PROPAGATION
29+
import com.intellij.openapi.ui.validation.CHECK_NON_EMPTY
30+
import com.intellij.openapi.ui.validation.and
31+
import com.intellij.openapi.ui.validation.validationErrorIf
32+
import com.intellij.openapi.util.Key
33+
import com.intellij.ui.dsl.builder.COLUMNS_MEDIUM
34+
import com.intellij.ui.dsl.builder.Panel
35+
import com.intellij.ui.dsl.builder.bindText
36+
import com.intellij.ui.dsl.builder.columns
37+
import com.intellij.ui.dsl.builder.textValidation
38+
39+
private val validModIdRegex = "[a-z][a-z0-9-_]{1,63}".toRegex()
40+
private val invalidModIdRegex = "[^a-z0-9-_]+".toRegex()
41+
42+
private val validForgeModIdRegex = "[a-z][a-z0-9_]{1,63}".toRegex()
43+
private val invalidForgeModIdRegex = "[^a-z0-9_]+".toRegex()
44+
45+
abstract class AbstractModIdStep(
46+
parent: NewProjectWizardStep,
47+
private val validRegex: Regex = validModIdRegex,
48+
private val invalidRegex: Regex = invalidModIdRegex
49+
) : AbstractNewProjectWizardStep(parent) {
50+
private val baseData = data.getUserData(NewProjectWizardBaseData.KEY)
51+
?: throw IllegalStateException("Mod id step created without base step")
52+
val idProperty = propertyGraph.lazyProperty(::suggestId)
53+
var id by idProperty
54+
55+
private val idValidation = validationErrorIf<String>("Id must match $validRegex") { !it.matches(validRegex) }
56+
57+
init {
58+
idProperty.dependsOn(baseData.nameProperty, ::suggestId)
59+
storeToData()
60+
}
61+
62+
fun suggestId(): String {
63+
val sanitized = baseData.name.lowercase().replace(invalidRegex, "_")
64+
if (sanitized.length > 64) {
65+
return sanitized.substring(0, 64)
66+
}
67+
return sanitized
68+
}
69+
70+
abstract val label: String
71+
72+
override fun setupUI(builder: Panel) {
73+
with(builder) {
74+
row(label) {
75+
textField()
76+
.bindText(idProperty)
77+
.columns(COLUMNS_MEDIUM)
78+
.validationRequestor(AFTER_GRAPH_PROPAGATION(propertyGraph))
79+
.textValidation(CHECK_NON_EMPTY and idValidation)
80+
}
81+
}
82+
}
83+
84+
override fun setupProject(project: Project) {
85+
data.putUserData(KEY, id)
86+
}
87+
88+
companion object {
89+
val KEY = Key.create<String>("${AbstractModIdStep::class.java.name}.id")
90+
}
91+
}
92+
93+
class ModIdStep(parent: NewProjectWizardStep) : AbstractModIdStep(parent) {
94+
override val label = "Mod Id:"
95+
}
96+
97+
class ForgeStyleModIdStep(parent: NewProjectWizardStep) :
98+
AbstractModIdStep(parent, validForgeModIdRegex, invalidForgeModIdRegex) {
99+
override val label = "Mod Id:"
100+
}
101+
102+
class PluginIdStep(parent: NewProjectWizardStep) : AbstractModIdStep(parent) {
103+
override val label = "Plugin Id:"
104+
}

src/main/kotlin/insight/ListenerEventAnnotator.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package com.demonwav.mcdev.insight
2222

2323
import com.demonwav.mcdev.MinecraftSettings
2424
import com.demonwav.mcdev.facet.MinecraftFacet
25+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
2526
import com.intellij.lang.annotation.AnnotationHolder
2627
import com.intellij.lang.annotation.Annotator
2728
import com.intellij.lang.annotation.HighlightSeverity
@@ -53,10 +54,11 @@ class ListenerEventAnnotator : Annotator {
5354
return
5455
}
5556

56-
val method: UMethod = element.toUElement()?.uastParent as? UMethod
57-
?: element.getUastParentOfType<UTypeReferenceExpression>()
58-
?.getParentOfType<UParameter>()?.uastParent as? UMethod // Be sure to be on the type of a parameter
59-
?: return
57+
val method: UMethod = runCatchingKtIdeaExceptions {
58+
element.toUElement()?.uastParent as? UMethod
59+
?: element.getUastParentOfType<UTypeReferenceExpression>()
60+
?.getParentOfType<UParameter>()?.uastParent as? UMethod // Be sure to be on the type of a parameter
61+
} ?: return
6062
if (method.javaPsi.hasModifierProperty(PsiModifier.ABSTRACT)) {
6163
// I don't think any implementation allows for abstract
6264
return

src/main/kotlin/insight/ListenerLineMarkerProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class ListenerLineMarkerProvider : LineMarkerProviderDescriptor() {
7676
return GutterIconNavigationHandler handler@{ _, element ->
7777
val (eventClass, _) = element.toUElementOfType<UIdentifier>()?.uastEventListener ?: return@handler
7878
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.declaration")
79-
eventClass.navigate(true)
79+
if (eventClass.canNavigate()) {
80+
eventClass.navigate(true)
81+
}
8082
}
8183
}
8284

0 commit comments

Comments
 (0)