Skip to content

Commit

Permalink
Merge branch '2021.2' into 2021.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DenWav committed Oct 1, 2022
2 parents 9931589 + b7db10a commit 279d28f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
freeCompilerArgs = listOf("-Xuse-k2", "-Xjvm-default=all", "-Xjdk-release=11")
kotlinDaemonJvmArguments.add("-Xmx1G")
kotlinDaemonJvmArguments.add("-Xmx2G")
}
}

Expand Down
75 changes: 75 additions & 0 deletions src/main/kotlin/platform/mcp/actions/CopyCoremodTargetAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2022 minecraft-dev
*
* MIT License
*/

package com.demonwav.mcdev.platform.mcp.actions

import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
import com.demonwav.mcdev.util.ActionData
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiField
import com.intellij.psi.PsiMethod
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive

class CopyCoremodTargetAction : SrgActionBase() {
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData) {
when (parent) {
is PsiField -> {
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
val classSrg = srgMap.getSrgClass(containing) ?: return showBalloon("No SRG name found", e)
val srg = srgMap.getSrgField(parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
Pair("target", "FIELD"),
Pair("class", classSrg),
Pair("fieldName", srg.name)
)
}
is PsiMethod -> {
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
val classSrg = srgMap.getSrgClass(containing) ?: return showBalloon("No SRG name found", e)
val srg = srgMap.getSrgMethod(parent) ?: return showBalloon("No SRG name found", e)
val srgDescriptor = srg.descriptor ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
Pair("target", "METHOD"),
Pair("class", classSrg),
Pair("methodName", srg.name),
Pair("methodDesc", srgDescriptor)
)
}
is PsiClass -> {
val classSrg = srgMap.getSrgClass(parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
Pair("target", "CLASS"),
Pair("name", classSrg),
)
}
else -> showBalloon("Not a valid element", e)
}
}

private fun copyToClipboard(editor: Editor, element: PsiElement, vararg keys: Pair<String, String>) {
val text = JsonObject(keys.toMap().mapValues { JsonPrimitive(it.value) }).toString()
val stringSelection = StringSelection(text)
val clpbrd = Toolkit.getDefaultToolkit().systemClipboard
clpbrd.setContents(stringSelection, null)
showSuccessBalloon(editor, element, "Copied Coremod Target Reference")
}
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@
description="Go to the relevant Access Transformer entry, if it exists">
<add-to-group group-id="EditorPopupMenu.GoTo"/>
</action>
<action class="com.demonwav.mcdev.platform.mcp.actions.CopyCoremodTargetAction" id="CopyCoremodTargetAction"
text="Coremod Target Reference"
description="Copy the reference to the element for use in a javascript coremod">
<add-to-group relative-to-action="CopyReference" anchor="after" group-id="Copy.Paste.Special"/>
</action>
<action class="com.demonwav.mcdev.platform.mcp.actions.LookupMemberAction" id="LookupMcpMember"
text="Lookup MCP Member"
description="Lookup MCP mapping info on a SRG field or method">
Expand Down

0 comments on commit 279d28f

Please sign in to comment.