diff --git a/src/main/kotlin/platform/mcp/actions/CopyAtAction.kt b/src/main/kotlin/platform/mcp/actions/CopyAtAction.kt
index be83cc013..acf2f0c7b 100644
--- a/src/main/kotlin/platform/mcp/actions/CopyAtAction.kt
+++ b/src/main/kotlin/platform/mcp/actions/CopyAtAction.kt
@@ -22,12 +22,12 @@ import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
class CopyAtAction : SrgActionBase() {
- override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData) {
+ 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)
+ val classSrg = getSrgClass(srgMap, containing) ?: return showBalloon("No SRG name found", e)
+ val srg = getSrgField(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
@@ -36,8 +36,8 @@ class CopyAtAction : SrgActionBase() {
}
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 classSrg = getSrgClass(srgMap, containing) ?: return showBalloon("No SRG name found", e)
+ val srg = getSrgMethod(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
@@ -45,7 +45,7 @@ class CopyAtAction : SrgActionBase() {
)
}
is PsiClass -> {
- val classMcpToSrg = srgMap.getSrgClass(parent) ?: return showBalloon("No SRG name found", e)
+ val classMcpToSrg = getSrgClass(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(data.editor, data.element, classMcpToSrg)
}
else -> showBalloon("Not a valid element", e)
diff --git a/src/main/kotlin/platform/mcp/actions/FindSrgMappingAction.kt b/src/main/kotlin/platform/mcp/actions/FindSrgMappingAction.kt
index 96f981334..ebc19c766 100644
--- a/src/main/kotlin/platform/mcp/actions/FindSrgMappingAction.kt
+++ b/src/main/kotlin/platform/mcp/actions/FindSrgMappingAction.kt
@@ -20,18 +20,21 @@ import com.intellij.psi.PsiMethod
class FindSrgMappingAction : SrgActionBase() {
- override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData) {
+ override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData) {
+ if (srgMap == null) {
+ return showBalloon("No mappings found", e)
+ }
when (parent) {
is PsiField -> {
- val srg = srgMap.getSrgField(parent) ?: return showBalloon("No SRG name found", e)
+ val srg = getSrgField(srgMap, parent) ?: return showBalloon("No SRG name found", e)
showSuccessBalloon(data.editor, data.element, "SRG name: " + srg.name)
}
is PsiMethod -> {
- val srg = srgMap.getSrgMethod(parent) ?: return showBalloon("No SRG name found", e)
+ val srg = getSrgMethod(srgMap, parent) ?: return showBalloon("No SRG name found", e)
showSuccessBalloon(data.editor, data.element, "SRG name: " + srg.name + srg.descriptor)
}
is PsiClass -> {
- val classMcpToSrg = srgMap.getSrgClass(parent) ?: return showBalloon("No SRG name found", e)
+ val classMcpToSrg = getSrgClass(srgMap, parent) ?: return showBalloon("No SRG name found", e)
showSuccessBalloon(data.editor, data.element, "SRG name: " + classMcpToSrg)
}
else -> showBalloon("Not a valid element", e)
diff --git a/src/main/kotlin/platform/mcp/actions/GotoAtEntryAction.kt b/src/main/kotlin/platform/mcp/actions/GotoAtEntryAction.kt
index df241f412..9bd7e1e92 100644
--- a/src/main/kotlin/platform/mcp/actions/GotoAtEntryAction.kt
+++ b/src/main/kotlin/platform/mcp/actions/GotoAtEntryAction.kt
@@ -12,24 +12,20 @@ package com.demonwav.mcdev.platform.mcp.actions
import com.demonwav.mcdev.facet.MinecraftFacet
import com.demonwav.mcdev.platform.mcp.McpModuleType
-import com.demonwav.mcdev.platform.mcp.srg.SrgManager
-import com.demonwav.mcdev.platform.mixin.util.findFirstShadowTarget
+import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
import com.demonwav.mcdev.util.ActionData
-import com.demonwav.mcdev.util.getDataFromActionEvent
import com.demonwav.mcdev.util.gotoTargetElement
import com.demonwav.mcdev.util.invokeLater
import com.demonwav.mcdev.util.qualifiedMemberReference
import com.demonwav.mcdev.util.simpleQualifiedMemberReference
-import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.wm.WindowManager
+import com.intellij.psi.PsiElement
import com.intellij.psi.PsiField
-import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiManager
-import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.PsiSearchHelper
@@ -37,47 +33,28 @@ import com.intellij.psi.search.UsageSearchContext
import com.intellij.ui.LightColors
import com.intellij.ui.awt.RelativePoint
-class GotoAtEntryAction : AnAction() {
- override fun actionPerformed(e: AnActionEvent) {
- val data = getDataFromActionEvent(e) ?: return showBalloon(e)
-
- if (data.element !is PsiIdentifier) {
- showBalloon(e)
- return
- }
-
- val srgManager = data.instance.getModuleOfType(McpModuleType)?.srgManager
- // Not all ATs are in MCP modules, fallback to this if possible
- // TODO try to find SRG references for all modules if current module isn't found?
- ?: SrgManager.findAnyInstance(data.project) ?: return showBalloon(e)
-
- srgManager.srgMap.onSuccess { srgMap ->
- var parent = data.element.parent
-
- if (parent is PsiMember) {
- val shadowTarget = parent.findFirstShadowTarget()?.element
- if (shadowTarget != null) {
- parent = shadowTarget
- }
+class GotoAtEntryAction : SrgActionBase() {
+ override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData) {
+ when (parent) {
+ is PsiField -> {
+ val reference = getSrgField(srgMap, parent) ?: parent.simpleQualifiedMemberReference
+ searchForText(e, data, reference.name)
}
-
- when (parent) {
- is PsiField -> {
- val reference = srgMap.getSrgField(parent) ?: parent.simpleQualifiedMemberReference
- searchForText(e, data, reference.name)
- }
- is PsiMethod -> {
- val reference = srgMap.getSrgMethod(parent) ?: parent.qualifiedMemberReference
- searchForText(e, data, reference.name + reference.descriptor)
- }
- else ->
- showBalloon(e)
+ is PsiMethod -> {
+ val reference = getSrgMethod(srgMap, parent) ?: parent.qualifiedMemberReference
+ searchForText(e, data, reference.name + reference.descriptor)
}
+ else ->
+ showBalloon(e)
}
}
private fun searchForText(e: AnActionEvent, data: ActionData, text: String) {
val manager = ModuleManager.getInstance(data.project)
+ val toList = manager.modules.asSequence()
+ .mapNotNull { MinecraftFacet.getInstance(it, McpModuleType) }
+ .toList()
+
manager.modules.asSequence()
.mapNotNull { MinecraftFacet.getInstance(it, McpModuleType) }
.flatMap { it.accessTransformers.asSequence() }
diff --git a/src/main/kotlin/platform/mcp/actions/SrgActionBase.kt b/src/main/kotlin/platform/mcp/actions/SrgActionBase.kt
index c52fb2416..dfdfc68a0 100644
--- a/src/main/kotlin/platform/mcp/actions/SrgActionBase.kt
+++ b/src/main/kotlin/platform/mcp/actions/SrgActionBase.kt
@@ -12,19 +12,26 @@ package com.demonwav.mcdev.platform.mcp.actions
import com.demonwav.mcdev.platform.mcp.McpModuleType
import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
+import com.demonwav.mcdev.platform.mcp.srg.SrgManager
import com.demonwav.mcdev.platform.mixin.util.findFirstShadowTarget
import com.demonwav.mcdev.util.ActionData
+import com.demonwav.mcdev.util.MemberReference
+import com.demonwav.mcdev.util.fullQualifiedName
import com.demonwav.mcdev.util.getDataFromActionEvent
import com.demonwav.mcdev.util.invokeLater
+import com.demonwav.mcdev.util.qualifiedMemberReference
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.wm.WindowManager
+import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiField
import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiMember
+import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiReference
import com.intellij.ui.LightColors
import com.intellij.ui.awt.RelativePoint
@@ -39,29 +46,59 @@ abstract class SrgActionBase : AnAction() {
return
}
- val mcpModule = data.instance.getModuleOfType(McpModuleType) ?: return showBalloon("No mappings found", e)
+ var parent = data.element.parent ?: return showBalloon("Not a valid element", e)
- mcpModule.srgManager?.srgMap?.onSuccess { srgMap ->
- var parent = data.element.parent
-
- if (parent is PsiMember) {
- val shadowTarget = parent.findFirstShadowTarget()?.element
- if (shadowTarget != null) {
- parent = shadowTarget
- }
+ if (parent is PsiMember) {
+ val shadowTarget = parent.findFirstShadowTarget()?.element
+ if (shadowTarget != null) {
+ parent = shadowTarget
}
+ }
+
+ if (parent is PsiReference) {
+ parent = parent.resolve() ?: return showBalloon("Not a valid element", e)
+ }
- if (parent is PsiReference) {
- parent = parent.resolve()
+ val srgManager = data.instance.getModuleOfType(McpModuleType)?.srgManager
+ // Not all ATs are in MCP modules, fallback to this if possible
+ // TODO try to find SRG references for all modules if current module isn't found?
+ ?: SrgManager.findAnyInstance(data.project)
+ if (srgManager == null) {
+ withSrgTarget(parent, null, e, data)
+ } else {
+ srgManager.srgMap.onSuccess { srgMap ->
+ withSrgTarget(parent, srgMap, e, data)
+ }.onError {
+ showBalloon(it.message ?: "No MCP data available", e)
}
+ }
+ }
+
+ abstract fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData)
- withSrgTarget(parent, srgMap, e, data)
- }?.onError {
- showBalloon(it.message ?: "No MCP data available", e)
- } ?: showBalloon("No mappings found", e)
+ protected fun getSrgClass(srgMap: McpSrgMap?, clazz: PsiClass): String? {
+ return if (srgMap != null) {
+ srgMap.getSrgClass(clazz)
+ } else {
+ clazz.fullQualifiedName
+ }
+ }
+
+ protected fun getSrgMethod(srgMap: McpSrgMap?, element: PsiMethod): MemberReference? {
+ return if (srgMap != null) {
+ srgMap.getSrgMethod(element)
+ } else {
+ element.qualifiedMemberReference
+ }
}
- abstract fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData)
+ protected fun getSrgField(srgMap: McpSrgMap?, element: PsiField): MemberReference? {
+ return if (srgMap != null) {
+ srgMap.getSrgField(element)
+ } else {
+ element.qualifiedMemberReference
+ }
+ }
protected fun showBalloon(message: String, e: AnActionEvent) {
val balloon = JBPopupFactory.getInstance()
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 909f1a167..eb024afbc 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -33,7 +33,7 @@
-
+
-
+
-
-
+
+
@@ -171,25 +171,23 @@
-
+
-
+
-
+
-
+
+
+
-
-
+
+
-
-
+
+
@@ -362,14 +360,14 @@