Skip to content

Commit 24f151b

Browse files
committed
Merge branch 'dev' into 2024.1
2 parents f8d87fb + e97dfd5 commit 24f151b

File tree

13 files changed

+100
-113
lines changed

13 files changed

+100
-113
lines changed

build.gradle.kts

+9-2
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,13 @@ tasks.clean { delete(generate) }
306306

307307
tasks.withType<PrepareSandboxTask> {
308308
pluginJar.set(tasks.jar.get().archiveFile)
309+
val pluginDirName = intellijPlatform.projectName.get()
309310
from(externalAnnotationsJar) {
310-
into("Minecraft Development/lib/resources")
311+
into("$pluginDirName/lib/resources")
311312
}
312313
from("templates") {
313314
exclude(".git")
314-
into("Minecraft Development/lib/resources/builtin-templates")
315+
into("$pluginDirName/lib/resources/builtin-templates")
315316
}
316317
}
317318

@@ -322,6 +323,12 @@ tasks.runIde {
322323
systemProperty("idea.ProcessCanceledException", "disabled")
323324
systemProperty("idea.debug.mode", "true")
324325
}
326+
327+
// Kotlin K2 is enabled by default, uncomment to switch to K1
328+
// jvmArgumentProviders += CommandLineArgumentProvider {
329+
// listOf("-Didea.kotlin.plugin.use.k2=false")
330+
// }
331+
325332
// Set these properties to test different languages
326333
// systemProperty("user.language", "fr")
327334
// systemProperty("user.country", "FR")

changelog.md

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
- `mods.toml` and `neoforge.mods.toml` documentation for lookup elements
99
- Support for split strings within inspections and method target references in Mixins ([#2358](https://github.com/minecraft-dev/MinecraftDev/pull/2358))
1010
- Mouse ungrab on breakpoint hit while running a Gradle task
11+
- JSON5 support to mixin config jsons ([#2375](https://github.com/minecraft-dev/MinecraftDev/pull/2375))
12+
- Value types in mods.toml key completion
13+
- Mixin injection signature fix preview
14+
- Loom 1.8 support
15+
- K2 mode compatibility
1116

1217
### Changed
1318

@@ -20,6 +25,9 @@
2025
- Ignored annotations registrations
2126
- NeoGradle and NeoModDev Minecraft version import
2227
- [#2360](https://github.com/minecraft-dev/MinecraftDev/issues/2360) `Class initialization must not depend on services` error
28+
- [#2376](https://github.com/minecraft-dev/MinecraftDev/issues/2376) Error when generating event listeners in read only file
29+
- [#2308](https://github.com/minecraft-dev/MinecraftDev/issues/2308) Mixin Inject signature fix adds last parameter as first local
30+
- [#1813](https://github.com/minecraft-dev/MinecraftDev/issues/1813) Single character Accessor targets aren't inferred correctly
2331

2432
## [1.8.1] - 2024-08-10
2533

src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelBuilderImpl.groovy

+22-6
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@
2020

2121
package com.demonwav.mcdev.platform.mcp.gradle.tooling.fabricloom
2222

23-
2423
import org.gradle.api.Project
2524
import org.jetbrains.annotations.NotNull
25+
import org.jetbrains.plugins.gradle.tooling.AbstractModelBuilderService
2626
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
27-
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService
27+
import org.jetbrains.plugins.gradle.tooling.Message
28+
import org.jetbrains.plugins.gradle.tooling.ModelBuilderContext
2829

29-
class FabricLoomModelBuilderImpl implements ModelBuilderService {
30+
class FabricLoomModelBuilderImpl extends AbstractModelBuilderService {
3031

3132
@Override
3233
boolean canBuild(String modelName) {
3334
return FabricLoomModel.name == modelName
3435
}
3536

3637
@Override
37-
Object buildAll(String modelName, Project project) {
38+
Object buildAll(@NotNull String modelName, @NotNull Project project, @NotNull ModelBuilderContext context) {
3839
if (!project.plugins.hasPlugin('fabric-loom')) {
3940
return null
4041
}
@@ -43,7 +44,16 @@ class FabricLoomModelBuilderImpl implements ModelBuilderService {
4344

4445
try {
4546
return build(project, loomExtension)
46-
} catch (GroovyRuntimeException ignored) {
47+
} catch (GroovyRuntimeException ex) {
48+
context.messageReporter.createMessage()
49+
.withTitle("Minecraft Dev - Loom importing error")
50+
.withText("An error occurred while importing Loom data, falling back to legacy import")
51+
.withGroup("com.demonwav.mcdev")
52+
.withKind(Message.Kind.WARNING)
53+
.withStackTrace()
54+
.withException(ex)
55+
.reportMessage(project)
56+
4757
// Must be using an older loom version, fallback.
4858
return buildLegacy(project, loomExtension)
4959
}
@@ -77,7 +87,13 @@ class FabricLoomModelBuilderImpl implements ModelBuilderService {
7787
List<FabricLoomModelImpl.DecompilerModelImpl> getDecompilers(Object loomExtension, boolean client) {
7888
loomExtension.decompilerOptions.collect {
7989
def task = loomExtension.getDecompileTask(it, client)
80-
def sourcesPath = task.outputJar.get().getAsFile().getAbsolutePath()
90+
def sourcesPath
91+
if (task.hasProperty("outputJar")) {
92+
// Pre 1.8
93+
sourcesPath = task.outputJar.get().getAsFile().getAbsolutePath()
94+
} else {
95+
sourcesPath = task.sourcesOutputJar.get().getAsFile().getAbsolutePath()
96+
}
8197
new FabricLoomModelImpl.DecompilerModelImpl(name: it.name, taskName: task.name, sourcesPath: sourcesPath)
8298
}
8399
}

src/main/kotlin/creator/custom/EvaluateTemplateExpressionAction.kt

-81
This file was deleted.

src/main/kotlin/insight/generation/EventGenHelper.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import com.intellij.psi.PsiElement
3333
import com.intellij.psi.PsiFile
3434
import com.intellij.psi.codeStyle.CodeStyleManager
3535
import com.intellij.psi.util.parentOfType
36+
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
37+
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferencesInRange
38+
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
39+
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
3640
import org.jetbrains.kotlin.idea.core.ShortenReferences
3741
import org.jetbrains.kotlin.psi.KtClassOrObject
3842
import org.jetbrains.kotlin.psi.KtFile
@@ -108,15 +112,22 @@ class KotlinEventGenHelper : EventGenHelper {
108112
val factory = KtPsiFactory.contextual(context)
109113
val entry = factory.createSuperTypeEntry(fqn)
110114
val insertedEntry = ktClass.addSuperTypeListEntry(entry)
111-
ShortenReferences.DEFAULT.process(insertedEntry)
115+
when (KotlinPluginModeProvider.currentPluginMode) {
116+
KotlinPluginMode.K1 -> ShortenReferences.DEFAULT.process(insertedEntry)
117+
// TODO find a non-internal alternative to this...
118+
KotlinPluginMode.K2 -> shortenReferences(insertedEntry)
119+
}
112120
}
113121

114122
override fun reformatAndShortenRefs(file: PsiFile, startOffset: Int, endOffset: Int) {
115123
file as? KtFile ?: return
116124
val project = file.project
117125

118126
val marker = JvmEventGenHelper.doReformat(project, file, startOffset, endOffset) ?: return
119-
120-
ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
127+
when (KotlinPluginModeProvider.currentPluginMode) {
128+
KotlinPluginMode.K1 -> ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
129+
// TODO find a non-internal alternative to this...
130+
KotlinPluginMode.K2 -> shortenReferencesInRange(file, marker.textRange)
131+
}
121132
}
122133
}

src/main/kotlin/platform/mixin/MixinModule.kt

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import com.demonwav.mcdev.facet.MinecraftFacetDetector
2525
import com.demonwav.mcdev.platform.AbstractModule
2626
import com.demonwav.mcdev.platform.PlatformType
2727
import com.demonwav.mcdev.platform.mixin.config.MixinConfig
28+
import com.demonwav.mcdev.platform.mixin.config.MixinConfigFileType
2829
import com.demonwav.mcdev.platform.mixin.framework.MIXIN_LIBRARY_KIND
2930
import com.demonwav.mcdev.util.SemanticVersion
3031
import com.demonwav.mcdev.util.nullable
3132
import com.intellij.json.psi.JsonFile
3233
import com.intellij.json.psi.JsonObject
33-
import com.intellij.openapi.fileTypes.FileTypeManager
3434
import com.intellij.openapi.project.Project
3535
import com.intellij.psi.JavaPsiFacade
3636
import com.intellij.psi.PsiClass
@@ -53,12 +53,7 @@ class MixinModule(facet: MinecraftFacet) : AbstractModule(facet) {
5353
override val icon: Icon? = null
5454

5555
companion object {
56-
private val mixinFileTypes by lazy {
57-
listOfNotNull(
58-
FileTypeManager.getInstance().findFileTypeByName("Mixin Json Configuration"),
59-
FileTypeManager.getInstance().findFileTypeByName("Mixin Json5 Configuration")
60-
)
61-
}
56+
private val mixinFileTypes = listOf(MixinConfigFileType.Json, MixinConfigFileType.Json5)
6257

6358
fun getMixinConfigs(
6459
project: Project,

src/main/kotlin/platform/mixin/config/MixinConfigFileType.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,30 @@ import com.intellij.openapi.fileTypes.ex.FileTypeIdentifiableByVirtualFile
2828
import com.intellij.openapi.vfs.VirtualFile
2929

3030
interface MixinConfigFileType : FileTypeIdentifiableByVirtualFile {
31-
fun getFilenameRegex() : Regex
31+
fun getFilenameRegex(): Regex
3232

3333
// Dynamic file type detection is sadly needed as we're overriding the built-in json file type.
3434
// Simply using an extension pattern is not sufficient as there is no way to bump the version to tell
3535
// the cache that the pattern has changed, as it now has, without changing the file type name.
3636
// See https://www.plugin-dev.com/intellij/custom-language/file-type-detection/#guidelines
3737
override fun isMyFileType(file: VirtualFile) = file.name.contains(getFilenameRegex())
3838

39-
override fun getDescription() = "Mixin configuration"
4039
override fun getDefaultExtension() = ""
4140
override fun getIcon() = PlatformAssets.MIXIN_ICON
4241

4342
object Json : LanguageFileType(JsonLanguage.INSTANCE), MixinConfigFileType {
4443
private val filenameRegex = "(^|\\.)mixins?(\\.[^.]+)*\\.json\$".toRegex()
4544

46-
override fun getFilenameRegex() : Regex = filenameRegex
45+
override fun getFilenameRegex(): Regex = filenameRegex
4746
override fun getName() = "Mixin Json Configuration"
47+
override fun getDescription() = "Mixin Json configuration"
4848
}
4949

5050
object Json5 : LanguageFileType(Json5Language.INSTANCE), MixinConfigFileType {
5151
private var filenameRegex = "(^|\\.)mixins?(\\.[^.]+)*\\.json5\$".toRegex()
5252

53-
override fun getFilenameRegex() : Regex = filenameRegex
53+
override fun getFilenameRegex(): Regex = filenameRegex
5454
override fun getName() = "Mixin Json5 Configuration"
55+
override fun getDescription() = "Mixin Json5 configuration"
5556
}
56-
}
57+
}

src/main/kotlin/platform/mixin/handlers/AccessorHandler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class AccessorHandler : MixinMemberAnnotationHandler {
8484
val result = PATTERN.matchEntire(memberName) ?: return null
8585
val prefix = result.groupValues[1]
8686
var name = result.groupValues[2]
87-
if (name.uppercase(Locale.ENGLISH) != name) {
87+
if (name.uppercase(Locale.ENGLISH) != name || name.length == 1) {
8888
name = name.decapitalize()
8989
}
9090
val type = if (prefix == "set") {

src/main/kotlin/platform/mixin/handlers/InjectAnnotationHandler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ class InjectAnnotationHandler : InjectorAnnotationHandler() {
8787
val resolvedInsns = resolveInstructions(annotation, targetClass, targetMethod).ifEmpty { return@let }
8888
for (insn in resolvedInsns) {
8989
val locals = LocalVariables.getLocals(module, targetClass, targetMethod, insn.insn)
90+
?.filterNotNull()
9091
?.drop(
9192
Type.getArgumentTypes(targetMethod.desc).size +
9293
if (targetMethod.hasAccess(Opcodes.ACC_STATIC)) 0 else 1,
9394
)
94-
?.filterNotNull()
9595
?.filter { it.desc != null }
9696
?: continue
9797
if (commonLocalsPrefix == null) {

src/main/kotlin/platform/mixin/inspection/injector/InvalidInjectorMethodSignatureInspection.kt

+18-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.demonwav.mcdev.util.synchronize
3939
import com.intellij.codeInsight.FileModificationService
4040
import com.intellij.codeInsight.intention.FileModifier.SafeFieldForPreview
4141
import com.intellij.codeInsight.intention.QuickFixFactory
42+
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo
4243
import com.intellij.codeInsight.lookup.LookupElement
4344
import com.intellij.codeInsight.lookup.LookupElementBuilder
4445
import com.intellij.codeInsight.template.Expression
@@ -71,6 +72,7 @@ import com.intellij.psi.PsiPrimitiveType
7172
import com.intellij.psi.PsiType
7273
import com.intellij.psi.codeStyle.JavaCodeStyleManager
7374
import com.intellij.psi.codeStyle.VariableKind
75+
import com.intellij.psi.util.PsiTreeUtil
7476
import com.intellij.psi.util.PsiUtil
7577
import com.intellij.psi.util.TypeConversionUtil
7678
import com.intellij.psi.util.parentOfType
@@ -327,12 +329,21 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
327329
return
328330
}
329331
val method = startElement as PsiMethod
330-
fixParameters(project, method.parameterList)
332+
fixParameters(project, method.parameterList, false)
331333
fixReturnType(method)
332334
fixIntLikeTypes(method, editor ?: return)
333335
}
334336

335-
private fun fixParameters(project: Project, parameters: PsiParameterList) {
337+
override fun generatePreview(project: Project, editor: Editor, file: PsiFile): IntentionPreviewInfo {
338+
val method = PsiTreeUtil.findSameElementInCopy(startElement, file) as? PsiMethod
339+
?: return IntentionPreviewInfo.EMPTY
340+
fixParameters(project, method.parameterList, true)
341+
fixReturnType(method)
342+
fixIntLikeTypes(method, editor)
343+
return IntentionPreviewInfo.DIFF
344+
}
345+
346+
private fun fixParameters(project: Project, parameters: PsiParameterList, preview: Boolean) {
336347
if (expectedParams == null) {
337348
return
338349
}
@@ -366,8 +377,12 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
366377
// Restore the captured locals and sugars before applying the fix
367378
newParams.addAll(locals)
368379
newParams.addAll(sugars)
369-
runWriteAction {
380+
if (preview) {
370381
parameters.synchronize(newParams)
382+
} else {
383+
runWriteAction {
384+
parameters.synchronize(newParams)
385+
}
371386
}
372387
}
373388

src/main/kotlin/util/SemanticVersion.kt

+18
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ class SemanticVersion(
151151
}
152152
}
153153

154+
// Regular Minecraft snapshot versions e.g. 24w39a
155+
fun parseMinecraftSnapshot(value: String): SemanticVersion? {
156+
if (value.length != 6 || value[2] != 'w' || !value[5].isLetter()) {
157+
return null
158+
}
159+
160+
val shortYear = value.substring(0, 2).toIntOrNull() ?: return null
161+
val week = value.substring(3, 5).toIntOrNull() ?: return null
162+
163+
val subParts = listOf(ReleasePart(week, week.toString()), TextPart(value[5].toString()))
164+
val mainPart = PreReleasePart(shortYear, 'w', subParts, value)
165+
return SemanticVersion(
166+
listOf(mainPart),
167+
)
168+
}
169+
170+
parseMinecraftSnapshot(value)?.let { return it }
171+
154172
val decodedValue = value.split('+').joinToString("+") { URLDecoder.decode(it, Charsets.UTF_8) }
155173
val mainPartAndMetadata = decodedValue.split("+", limit = 2)
156174
val mainPart = mainPartAndMetadata[0]

0 commit comments

Comments
 (0)