Skip to content

Commit 482f24c

Browse files
committed
Merge branch '2022.2' into 2022.3
2 parents 20975ac + b8662e3 commit 482f24c

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ tasks.withType<KotlinCompile>().configureEach {
190190
jvmTarget = JavaVersion.VERSION_17.toString()
191191
// K2 causes the following error: https://youtrack.jetbrains.com/issue/KT-52786
192192
freeCompilerArgs = listOf(/*"-Xuse-k2", */"-Xjvm-default=all", "-Xjdk-release=17")
193-
kotlinDaemonJvmArguments.add("-Xmx1G")
193+
kotlinDaemonJvmArguments.add("-Xmx2G")
194194
}
195195
}
196196

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Minecraft Dev for IntelliJ
3+
*
4+
* https://minecraftdev.org
5+
*
6+
* Copyright (c) 2022 minecraft-dev
7+
*
8+
* MIT License
9+
*/
10+
11+
package com.demonwav.mcdev.platform.mcp.actions
12+
13+
import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
14+
import com.demonwav.mcdev.util.ActionData
15+
import com.intellij.openapi.actionSystem.AnActionEvent
16+
import com.intellij.openapi.editor.Editor
17+
import com.intellij.psi.PsiClass
18+
import com.intellij.psi.PsiElement
19+
import com.intellij.psi.PsiField
20+
import com.intellij.psi.PsiMethod
21+
import java.awt.Toolkit
22+
import java.awt.datatransfer.StringSelection
23+
import kotlinx.serialization.json.JsonObject
24+
import kotlinx.serialization.json.JsonPrimitive
25+
26+
class CopyCoremodTargetAction : SrgActionBase() {
27+
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData) {
28+
when (parent) {
29+
is PsiField -> {
30+
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
31+
val classSrg = srgMap.getSrgClass(containing) ?: return showBalloon("No SRG name found", e)
32+
val srg = srgMap.getSrgField(parent) ?: return showBalloon("No SRG name found", e)
33+
copyToClipboard(
34+
data.editor,
35+
data.element,
36+
Pair("target", "FIELD"),
37+
Pair("class", classSrg),
38+
Pair("fieldName", srg.name)
39+
)
40+
}
41+
is PsiMethod -> {
42+
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
43+
val classSrg = srgMap.getSrgClass(containing) ?: return showBalloon("No SRG name found", e)
44+
val srg = srgMap.getSrgMethod(parent) ?: return showBalloon("No SRG name found", e)
45+
val srgDescriptor = srg.descriptor ?: return showBalloon("No SRG name found", e)
46+
copyToClipboard(
47+
data.editor,
48+
data.element,
49+
Pair("target", "METHOD"),
50+
Pair("class", classSrg),
51+
Pair("methodName", srg.name),
52+
Pair("methodDesc", srgDescriptor)
53+
)
54+
}
55+
is PsiClass -> {
56+
val classSrg = srgMap.getSrgClass(parent) ?: return showBalloon("No SRG name found", e)
57+
copyToClipboard(
58+
data.editor,
59+
data.element,
60+
Pair("target", "CLASS"),
61+
Pair("name", classSrg),
62+
)
63+
}
64+
else -> showBalloon("Not a valid element", e)
65+
}
66+
}
67+
68+
private fun copyToClipboard(editor: Editor, element: PsiElement, vararg keys: Pair<String, String>) {
69+
val text = JsonObject(keys.toMap().mapValues { JsonPrimitive(it.value) }).toString()
70+
val stringSelection = StringSelection(text)
71+
val clpbrd = Toolkit.getDefaultToolkit().systemClipboard
72+
clpbrd.setContents(stringSelection, null)
73+
showSuccessBalloon(editor, element, "Copied Coremod Target Reference")
74+
}
75+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,11 @@
959959
description="Go to the relevant Access Transformer entry, if it exists">
960960
<add-to-group group-id="EditorPopupMenu.GoTo"/>
961961
</action>
962+
<action class="com.demonwav.mcdev.platform.mcp.actions.CopyCoremodTargetAction" id="CopyCoremodTargetAction"
963+
text="Coremod Target Reference"
964+
description="Copy the reference to the element for use in a javascript coremod">
965+
<add-to-group relative-to-action="CopyReference" anchor="after" group-id="Copy.Paste.Special"/>
966+
</action>
962967
<action class="com.demonwav.mcdev.platform.mcp.actions.LookupMemberAction" id="LookupMcpMember"
963968
text="Lookup MCP Member"
964969
description="Lookup MCP mapping info on a SRG field or method">

0 commit comments

Comments
 (0)