Skip to content

Commit 370a370

Browse files
committed
Merge branch '2023.2' into 2023.3
2 parents a3c37a4 + 40d6b84 commit 370a370

File tree

64 files changed

+1976
-408
lines changed

Some content is hidden

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

64 files changed

+1976
-408
lines changed

build.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ dependencies {
118118

119119
implementation(libs.mixinExtras.expressions)
120120
testLibs(libs.mixinExtras.common)
121-
implementation("org.ow2.asm:asm-util:9.3")
122121

123122
// Kotlin
124123
implementation(kotlin("stdlib-jdk8"))
@@ -298,10 +297,9 @@ tasks.processResources {
298297
tasks.test {
299298
dependsOn(tasks.jar, testLibs)
300299
useJUnitPlatform()
301-
doFirst {
302-
testLibs.resolvedConfiguration.resolvedArtifacts.forEach {
303-
systemProperty("testLibs.${it.name}", it.file.absolutePath)
304-
}
300+
301+
testLibs.resolvedConfiguration.resolvedArtifacts.forEach {
302+
systemProperty("testLibs.${it.name}", it.file.absolutePath)
305303
}
306304
systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true")
307305
systemProperty("java.awt.headless", "true")

changelog.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Minecraft Development for IntelliJ
22

3+
## [Unreleased]
4+
5+
### Added
6+
7+
- Access widener completion in fabric.mod.json
8+
- Event listener generation for Kotlin
9+
- `JUMP` injection point support (without source navigation)
10+
- Inspection highlighting that `JUMP` usages are discouraged
11+
- Inspection highlighting discouraged instruction shifts
12+
- Inspections for when @Inject local capture is unused and for when they can be replaced with @Local
13+
- [#2306](https://github.com/minecraft-dev/MinecraftDev/issues/2306) Use mixin icon for mixin classes
14+
15+
### Fixed
16+
17+
- [#2330](https://github.com/minecraft-dev/MinecraftDev/issues/2330) Reformat created files without keeping line breaks. Fixes the Velocity main class annotation's bad formatting.
18+
- [#2331](https://github.com/minecraft-dev/MinecraftDev/issues/2331) Support fabric.mod.json in test resources
19+
- MixinExtras occasional cache desync ([#2335](https://github.com/minecraft-dev/MinecraftDev/pull/2335))
20+
- [#2163](https://github.com/minecraft-dev/MinecraftDev/issues/2163) `@ModifyVariable` method signature checking with `STORE`
21+
- [#2282](https://github.com/minecraft-dev/MinecraftDev/issues/2282) Mixin support confusion with `$` and `.` separators in class names
22+
- Recent NeoModDev version import errors
23+
324
## [1.8.0]
425

526
This release contains two major features:

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ groovy = "org.codehaus.groovy:groovy-all:2.5.18"
2626
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
2727
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }
2828
asm-analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" }
29+
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }
2930

3031
fuel = { module = "com.github.kittinunf.fuel:fuel", version.ref = "fuel" }
3132
fuel-coroutines = { module = "com.github.kittinunf.fuel:fuel-coroutines", version.ref = "fuel" }
@@ -45,5 +46,5 @@ mixinExtras-common = "io.github.llamalad7:mixinextras-common:0.5.0-beta.1"
4546

4647
[bundles]
4748
coroutines = ["coroutines-swing"]
48-
asm = ["asm", "asm-tree", "asm-analysis"]
49+
asm = ["asm", "asm-tree", "asm-analysis", "asm-util"]
4950
fuel = ["fuel", "fuel-coroutines"]

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.7.6-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
38+
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.8.0-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/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/neomoddev/NeoModDevGradleModelBuilderImpl.groovy

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package com.demonwav.mcdev.platform.mcp.gradle.tooling.neomoddev
2222

2323
import com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelNMD
2424
import org.gradle.api.Project
25+
import org.gradle.api.provider.ListProperty
2526
import org.jetbrains.annotations.NotNull
2627
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
2728
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService
@@ -51,16 +52,26 @@ final class NeoModDevGradleModelBuilderImpl implements ModelBuilderService {
5152
return null
5253
}
5354

54-
def accessTransformers = extension.accessTransformers.get().collect { project.file(it) }
55+
def accessTransformersRaw = extension.accessTransformers
56+
List<File> accessTransformers
57+
if (accessTransformersRaw instanceof ListProperty) {
58+
accessTransformers = accessTransformersRaw.get().collect { project.file(it) }
59+
} else {
60+
accessTransformers = accessTransformersRaw.files.files.toList()
61+
}
5562

56-
// Hacky way to guess where the mappings file is, but I could not find a proper way to find it
57-
def neoformDir = project.buildDir.toPath().resolve("neoForm")
58-
def mappingsFile = Files.list(neoformDir)
59-
.map { it.resolve("config/joined.tsrg") }
60-
.filter { Files.exists(it) }
61-
.findFirst()
62-
.orElse(null)
63-
?.toFile()
63+
File mappingsFile = null
64+
try {
65+
// Hacky way to guess where the mappings file is, but I could not find a proper way to find it
66+
def neoformDir = project.buildDir.toPath().resolve("neoForm")
67+
mappingsFile = Files.list(neoformDir)
68+
.map { it.resolve("config/joined.tsrg") }
69+
.filter { Files.exists(it) }
70+
.findFirst()
71+
.orElse(null)
72+
?.toFile()
73+
} catch (Exception ignore) {
74+
}
6475

6576
//noinspection GroovyAssignabilityCheck
6677
return new NeoModDevGradleModelImpl(neoforgeVersion, mappingsFile, accessTransformers)

src/main/kotlin/MinecraftConfigurable.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class MinecraftConfigurable : Configurable {
8686
}
8787
}
8888

89+
group(MCDevBundle("minecraft.settings.mixin")) {
90+
row {
91+
checkBox(MCDevBundle("minecraft.settings.mixin.mixin_class_icon"))
92+
.bindSelected(settings::mixinClassIcon)
93+
}
94+
}
95+
8996
group(MCDevBundle("minecraft.settings.creator")) {
9097
row(MCDevBundle("minecraft.settings.creator.repos")) {}
9198

src/main/kotlin/MinecraftSettings.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
4040
var isShowChatColorUnderlines: Boolean = false,
4141
var underlineType: UnderlineType = UnderlineType.DOTTED,
4242

43+
var mixinClassIcon: Boolean = true,
44+
4345
var creatorTemplateRepos: List<TemplateRepo> = listOf(TemplateRepo.makeBuiltinRepo()),
4446
)
4547

@@ -106,6 +108,12 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
106108
state.underlineType = underlineType
107109
}
108110

111+
var mixinClassIcon: Boolean
112+
get() = state.mixinClassIcon
113+
set(mixinClassIcon) {
114+
state.mixinClassIcon = mixinClassIcon
115+
}
116+
109117
var creatorTemplateRepos: List<TemplateRepo>
110118
get() = state.creatorTemplateRepos.map { it.copy() }
111119
set(creatorTemplateRepos) {

src/main/kotlin/asset/MixinAssets.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ object MixinAssets : Assets() {
2727

2828
val MIXIN_CLASS_ICON = loadIcon("/assets/icons/mixin/mixin_class_gutter.png")
2929
val MIXIN_CLASS_ICON_DARK = loadIcon("/assets/icons/mixin/mixin_class_gutter_dark.png")
30+
31+
val MIXIN_MARK = loadIcon("/assets/icons/mixin/mixin_mark.svg")
3032
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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.insight.generation
22+
23+
import com.demonwav.mcdev.util.addImplements
24+
import com.intellij.core.CoreJavaCodeStyleManager
25+
import com.intellij.lang.LanguageExtension
26+
import com.intellij.lang.LanguageExtensionPoint
27+
import com.intellij.openapi.editor.RangeMarker
28+
import com.intellij.openapi.extensions.ExtensionPointName
29+
import com.intellij.openapi.project.Project
30+
import com.intellij.psi.PsiClass
31+
import com.intellij.psi.PsiDocumentManager
32+
import com.intellij.psi.PsiElement
33+
import com.intellij.psi.PsiFile
34+
import com.intellij.psi.codeStyle.CodeStyleManager
35+
import com.intellij.psi.util.parentOfType
36+
import org.jetbrains.kotlin.idea.core.ShortenReferences
37+
import org.jetbrains.kotlin.psi.KtClassOrObject
38+
import org.jetbrains.kotlin.psi.KtFile
39+
import org.jetbrains.kotlin.psi.KtPsiFactory
40+
41+
interface EventGenHelper {
42+
43+
fun addImplements(context: PsiElement, fqn: String)
44+
45+
fun reformatAndShortenRefs(file: PsiFile, startOffset: Int, endOffset: Int)
46+
47+
companion object {
48+
49+
val EP_NAME = ExtensionPointName.create<LanguageExtensionPoint<EventGenHelper>>(
50+
"com.demonwav.minecraft-dev.eventGenHelper"
51+
)
52+
val COLLECTOR = LanguageExtension<EventGenHelper>(EP_NAME, JvmEventGenHelper())
53+
}
54+
}
55+
56+
open class JvmEventGenHelper : EventGenHelper {
57+
58+
override fun addImplements(context: PsiElement, fqn: String) {}
59+
60+
override fun reformatAndShortenRefs(file: PsiFile, startOffset: Int, endOffset: Int) {
61+
val project = file.project
62+
63+
val marker = doReformat(project, file, startOffset, endOffset) ?: return
64+
65+
CoreJavaCodeStyleManager.getInstance(project).shortenClassReferences(file, marker.startOffset, marker.endOffset)
66+
}
67+
68+
companion object {
69+
70+
fun doReformat(project: Project, file: PsiFile, startOffset: Int, endOffset: Int): RangeMarker? {
71+
val documentManager = PsiDocumentManager.getInstance(project)
72+
val document = documentManager.getDocument(file) ?: return null
73+
74+
val marker = document.createRangeMarker(startOffset, endOffset).apply {
75+
isGreedyToLeft = true
76+
isGreedyToRight = true
77+
}
78+
79+
CodeStyleManager.getInstance(project).reformatText(file, startOffset, endOffset)
80+
documentManager.commitDocument(document)
81+
82+
return marker
83+
}
84+
}
85+
}
86+
87+
class JavaEventGenHelper : JvmEventGenHelper() {
88+
89+
override fun addImplements(context: PsiElement, fqn: String) {
90+
val psiClass = context.parentOfType<PsiClass>(true) ?: return
91+
psiClass.addImplements(fqn)
92+
}
93+
}
94+
95+
class KotlinEventGenHelper : EventGenHelper {
96+
97+
private fun hasSuperType(ktClass: KtClassOrObject, fqn: String): Boolean {
98+
val names = setOf(fqn, fqn.substringAfterLast('.'))
99+
return ktClass.superTypeListEntries.any { it.text in names }
100+
}
101+
102+
override fun addImplements(context: PsiElement, fqn: String) {
103+
val ktClass = context.parentOfType<KtClassOrObject>(true) ?: return
104+
if (hasSuperType(ktClass, fqn)) {
105+
return
106+
}
107+
108+
val factory = KtPsiFactory.contextual(context)
109+
val entry = factory.createSuperTypeEntry(fqn)
110+
val insertedEntry = ktClass.addSuperTypeListEntry(entry)
111+
ShortenReferences.DEFAULT.process(insertedEntry)
112+
}
113+
114+
override fun reformatAndShortenRefs(file: PsiFile, startOffset: Int, endOffset: Int) {
115+
file as? KtFile ?: return
116+
val project = file.project
117+
118+
val marker = JvmEventGenHelper.doReformat(project, file, startOffset, endOffset) ?: return
119+
120+
ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
121+
}
122+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.insight.generation
22+
23+
import com.intellij.openapi.editor.Editor
24+
import com.intellij.psi.PsiClass
25+
import com.intellij.psi.PsiElement
26+
27+
interface EventListenerGenerationSupport {
28+
29+
fun canGenerate(context: PsiElement, editor: Editor): Boolean
30+
31+
fun generateEventListener(
32+
context: PsiElement,
33+
listenerName: String,
34+
eventClass: PsiClass,
35+
data: GenerationData?,
36+
editor: Editor
37+
)
38+
}

0 commit comments

Comments
 (0)