Skip to content

Commit

Permalink
Merge branch '2024.2' into 2024.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Oct 1, 2024
2 parents 9c4c07d + acfb0a0 commit 555d6d2
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 113 deletions.
11 changes: 9 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,13 @@ tasks.clean { delete(generate) }

tasks.withType<PrepareSandboxTask> {
pluginJar.set(tasks.jar.get().archiveFile)
val pluginDirName = intellijPlatform.projectName.get()
from(externalAnnotationsJar) {
into("MinecraftDev/lib/resources")
into("$pluginDirName/lib/resources")
}
from("templates") {
exclude(".git")
into("MinecraftDev/lib/resources/builtin-templates")
into("$pluginDirName/lib/resources/builtin-templates")
}
}

Expand All @@ -323,6 +324,12 @@ tasks.runIde {
systemProperty("idea.ProcessCanceledException", "disabled")
systemProperty("idea.debug.mode", "true")
}

// Kotlin K2 is enabled by default, uncomment to switch to K1
// jvmArgumentProviders += CommandLineArgumentProvider {
// listOf("-Didea.kotlin.plugin.use.k2=false")
// }

// Set these properties to test different languages
// systemProperty("user.language", "fr")
// systemProperty("user.country", "FR")
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
- `mods.toml` and `neoforge.mods.toml` documentation for lookup elements
- Support for split strings within inspections and method target references in Mixins ([#2358](https://github.com/minecraft-dev/MinecraftDev/pull/2358))
- Mouse ungrab on breakpoint hit while running a Gradle task
- JSON5 support to mixin config jsons ([#2375](https://github.com/minecraft-dev/MinecraftDev/pull/2375))
- Value types in mods.toml key completion
- Mixin injection signature fix preview
- Loom 1.8 support
- K2 mode compatibility

### Changed

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

## [1.8.1] - 2024-08-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@

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


import org.gradle.api.Project
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.gradle.tooling.AbstractModelBuilderService
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService
import org.jetbrains.plugins.gradle.tooling.Message
import org.jetbrains.plugins.gradle.tooling.ModelBuilderContext

class FabricLoomModelBuilderImpl implements ModelBuilderService {
class FabricLoomModelBuilderImpl extends AbstractModelBuilderService {

@Override
boolean canBuild(String modelName) {
return FabricLoomModel.name == modelName
}

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

try {
return build(project, loomExtension)
} catch (GroovyRuntimeException ignored) {
} catch (GroovyRuntimeException ex) {
context.messageReporter.createMessage()
.withTitle("Minecraft Dev - Loom importing error")
.withText("An error occurred while importing Loom data, falling back to legacy import")
.withGroup("com.demonwav.mcdev")
.withKind(Message.Kind.WARNING)
.withStackTrace()
.withException(ex)
.reportMessage(project)

// Must be using an older loom version, fallback.
return buildLegacy(project, loomExtension)
}
Expand Down Expand Up @@ -77,7 +87,13 @@ class FabricLoomModelBuilderImpl implements ModelBuilderService {
List<FabricLoomModelImpl.DecompilerModelImpl> getDecompilers(Object loomExtension, boolean client) {
loomExtension.decompilerOptions.collect {
def task = loomExtension.getDecompileTask(it, client)
def sourcesPath = task.outputJar.get().getAsFile().getAbsolutePath()
def sourcesPath
if (task.hasProperty("outputJar")) {
// Pre 1.8
sourcesPath = task.outputJar.get().getAsFile().getAbsolutePath()
} else {
sourcesPath = task.sourcesOutputJar.get().getAsFile().getAbsolutePath()
}
new FabricLoomModelImpl.DecompilerModelImpl(name: it.name, taskName: task.name, sourcesPath: sourcesPath)
}
}
Expand Down
81 changes: 0 additions & 81 deletions src/main/kotlin/creator/custom/EvaluateTemplateExpressionAction.kt

This file was deleted.

17 changes: 14 additions & 3 deletions src/main/kotlin/insight/generation/EventGenHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.util.parentOfType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferencesInRange
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
Expand Down Expand Up @@ -108,15 +112,22 @@ class KotlinEventGenHelper : EventGenHelper {
val factory = KtPsiFactory.contextual(context)
val entry = factory.createSuperTypeEntry(fqn)
val insertedEntry = ktClass.addSuperTypeListEntry(entry)
ShortenReferences.DEFAULT.process(insertedEntry)
when (KotlinPluginModeProvider.currentPluginMode) {
KotlinPluginMode.K1 -> ShortenReferences.DEFAULT.process(insertedEntry)
// TODO find a non-internal alternative to this...
KotlinPluginMode.K2 -> shortenReferences(insertedEntry)
}
}

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

val marker = JvmEventGenHelper.doReformat(project, file, startOffset, endOffset) ?: return

ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
when (KotlinPluginModeProvider.currentPluginMode) {
KotlinPluginMode.K1 -> ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset)
// TODO find a non-internal alternative to this...
KotlinPluginMode.K2 -> shortenReferencesInRange(file, marker.textRange)
}
}
}
9 changes: 2 additions & 7 deletions src/main/kotlin/platform/mixin/MixinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import com.demonwav.mcdev.facet.MinecraftFacetDetector
import com.demonwav.mcdev.platform.AbstractModule
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.platform.mixin.config.MixinConfig
import com.demonwav.mcdev.platform.mixin.config.MixinConfigFileType
import com.demonwav.mcdev.platform.mixin.framework.MIXIN_LIBRARY_KIND
import com.demonwav.mcdev.util.SemanticVersion
import com.demonwav.mcdev.util.nullable
import com.intellij.json.psi.JsonFile
import com.intellij.json.psi.JsonObject
import com.intellij.openapi.fileTypes.FileTypeManager
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClass
Expand All @@ -53,12 +53,7 @@ class MixinModule(facet: MinecraftFacet) : AbstractModule(facet) {
override val icon: Icon? = null

companion object {
private val mixinFileTypes by lazy {
listOfNotNull(
FileTypeManager.getInstance().findFileTypeByName("Mixin Json Configuration"),
FileTypeManager.getInstance().findFileTypeByName("Mixin Json5 Configuration")
)
}
private val mixinFileTypes = listOf(MixinConfigFileType.Json, MixinConfigFileType.Json5)

fun getMixinConfigs(
project: Project,
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/platform/mixin/config/MixinConfigFileType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@ import com.intellij.openapi.fileTypes.ex.FileTypeIdentifiableByVirtualFile
import com.intellij.openapi.vfs.VirtualFile

interface MixinConfigFileType : FileTypeIdentifiableByVirtualFile {
fun getFilenameRegex() : Regex
fun getFilenameRegex(): Regex

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

override fun getDescription() = "Mixin configuration"
override fun getDefaultExtension() = ""
override fun getIcon() = PlatformAssets.MIXIN_ICON

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

override fun getFilenameRegex() : Regex = filenameRegex
override fun getFilenameRegex(): Regex = filenameRegex
override fun getName() = "Mixin Json Configuration"
override fun getDescription() = "Mixin Json configuration"
}

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

override fun getFilenameRegex() : Regex = filenameRegex
override fun getFilenameRegex(): Regex = filenameRegex
override fun getName() = "Mixin Json5 Configuration"
override fun getDescription() = "Mixin Json5 configuration"
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/platform/mixin/handlers/AccessorHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AccessorHandler : MixinMemberAnnotationHandler {
val result = PATTERN.matchEntire(memberName) ?: return null
val prefix = result.groupValues[1]
var name = result.groupValues[2]
if (name.uppercase(Locale.ENGLISH) != name) {
if (name.uppercase(Locale.ENGLISH) != name || name.length == 1) {
name = name.decapitalize()
}
val type = if (prefix == "set") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class InjectAnnotationHandler : InjectorAnnotationHandler() {
val resolvedInsns = resolveInstructions(annotation, targetClass, targetMethod).ifEmpty { return@let }
for (insn in resolvedInsns) {
val locals = LocalVariables.getLocals(module, targetClass, targetMethod, insn.insn)
?.filterNotNull()
?.drop(
Type.getArgumentTypes(targetMethod.desc).size +
if (targetMethod.hasAccess(Opcodes.ACC_STATIC)) 0 else 1,
)
?.filterNotNull()
?.filter { it.desc != null }
?: continue
if (commonLocalsPrefix == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.demonwav.mcdev.util.synchronize
import com.intellij.codeInsight.FileModificationService
import com.intellij.codeInsight.intention.FileModifier.SafeFieldForPreview
import com.intellij.codeInsight.intention.QuickFixFactory
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.codeInsight.template.Expression
Expand Down Expand Up @@ -71,6 +72,7 @@ import com.intellij.psi.PsiPrimitiveType
import com.intellij.psi.PsiType
import com.intellij.psi.codeStyle.JavaCodeStyleManager
import com.intellij.psi.codeStyle.VariableKind
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.PsiUtil
import com.intellij.psi.util.TypeConversionUtil
import com.intellij.psi.util.parentOfType
Expand Down Expand Up @@ -327,12 +329,21 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
return
}
val method = startElement as PsiMethod
fixParameters(project, method.parameterList)
fixParameters(project, method.parameterList, false)
fixReturnType(method)
fixIntLikeTypes(method, editor ?: return)
}

private fun fixParameters(project: Project, parameters: PsiParameterList) {
override fun generatePreview(project: Project, editor: Editor, file: PsiFile): IntentionPreviewInfo {
val method = PsiTreeUtil.findSameElementInCopy(startElement, file) as? PsiMethod
?: return IntentionPreviewInfo.EMPTY
fixParameters(project, method.parameterList, true)
fixReturnType(method)
fixIntLikeTypes(method, editor)
return IntentionPreviewInfo.DIFF
}

private fun fixParameters(project: Project, parameters: PsiParameterList, preview: Boolean) {
if (expectedParams == null) {
return
}
Expand Down Expand Up @@ -366,8 +377,12 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
// Restore the captured locals and sugars before applying the fix
newParams.addAll(locals)
newParams.addAll(sugars)
runWriteAction {
if (preview) {
parameters.synchronize(newParams)
} else {
runWriteAction {
parameters.synchronize(newParams)
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/util/SemanticVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ class SemanticVersion(
}
}

// Regular Minecraft snapshot versions e.g. 24w39a
fun parseMinecraftSnapshot(value: String): SemanticVersion? {
if (value.length != 6 || value[2] != 'w' || !value[5].isLetter()) {
return null
}

val shortYear = value.substring(0, 2).toIntOrNull() ?: return null
val week = value.substring(3, 5).toIntOrNull() ?: return null

val subParts = listOf(ReleasePart(week, week.toString()), TextPart(value[5].toString()))
val mainPart = PreReleasePart(shortYear, 'w', subParts, value)
return SemanticVersion(
listOf(mainPart),
)
}

parseMinecraftSnapshot(value)?.let { return it }

val decodedValue = value.split('+').joinToString("+") { URLDecoder.decode(it, Charsets.UTF_8) }
val mainPartAndMetadata = decodedValue.split("+", limit = 2)
val mainPart = mainPartAndMetadata[0]
Expand Down
Loading

0 comments on commit 555d6d2

Please sign in to comment.