-
Notifications
You must be signed in to change notification settings - Fork 205
Added an Action for copying ATs while on NeoForge 1.21.4+ #2537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2db8a73
2025.1 EAP
RedNesto 8920f15
Fixed CCE in lockedCached and test dependencies
RedNesto 9b5e514
Fix: Resolve compile errors from new 2025.1 build.
LlamaLad7 0a1c81e
Fix: Fix `lockedCached` not working on 2025.1.
LlamaLad7 f225586
Fix deprecations in 2025.1
DenWav 98be0a2
Build against 2025.1 release
Earthcomputer 3b11486
Move away from reflection to call ByteCodeViewerManager.loadClassFile…
Earthcomputer 2c0f71b
2025.2
RedNesto 5f60437
Fix deprecation warnings
RedNesto 43f7bd8
Add annotations dependency to hopefully fix CI
RedNesto dc8191e
Revert to old JSON plugin id
RedNesto c957f88
Replace usages of now-deprecated InspectionGadgetsFix
RedNesto 36e530e
Build against 2025.2 release
Earthcomputer 0df4bfd
neo at's
Nyfaria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/kotlin/platform/mcp/actions/platform/mcp/actions/CopyNeoAtAction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Minecraft Development for IntelliJ | ||
| * | ||
| * https://mcdev.io/ | ||
| * | ||
| * Copyright (C) 2025 minecraft-dev | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published | ||
| * by the Free Software Foundation, version 3.0 only. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.demonwav.mcdev.platform.mcp.actions.platform.mcp.actions | ||
|
|
||
| import com.demonwav.mcdev.platform.mcp.actions.SrgActionBase.Companion.showBalloon | ||
| import com.demonwav.mcdev.platform.mcp.actions.SrgActionBase.Companion.showSuccessBalloon | ||
| import com.demonwav.mcdev.util.descriptor | ||
| import com.demonwav.mcdev.util.getDataFromActionEvent | ||
| import com.demonwav.mcdev.util.internalName | ||
| import com.intellij.openapi.actionSystem.AnAction | ||
| 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.PsiIdentifier | ||
| import com.intellij.psi.PsiMember | ||
| import com.intellij.psi.PsiMethod | ||
| import com.intellij.psi.PsiReference | ||
| import java.awt.Toolkit | ||
| import java.awt.datatransfer.StringSelection | ||
|
|
||
| class CopyNeoAtAction : AnAction() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be a separate action? Could you not just fix the existing AT action to work on 1.21.4+?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ill reopen a new PR with it done better. |
||
|
|
||
| override fun actionPerformed(e: AnActionEvent) { | ||
| val data = getDataFromActionEvent(e) ?: return showBalloon("Unknown failure", e) | ||
| val editor = data.editor | ||
|
|
||
| val element = data.element | ||
| if (element !is PsiIdentifier) { | ||
| showBalloon("Invalid element", e) | ||
| return | ||
| } | ||
|
|
||
| val target = when (val parent = element.parent) { | ||
| is PsiMember -> parent | ||
| is PsiReference -> parent.resolve() | ||
| else -> null | ||
| } ?: return showBalloon("Invalid element", e) | ||
|
|
||
| doCopy(target, element, editor, e) | ||
| } | ||
|
|
||
| companion object { | ||
|
|
||
| fun doCopy(target: PsiElement, element: PsiElement, editor: Editor?, e: AnActionEvent?) { | ||
| when (target) { | ||
| is PsiClass -> { | ||
| val text = "public ${target.internalName}" | ||
| val text2 = text.replace("/",".").replace(" (","(") | ||
| copyToClipboard(editor, element, text2) | ||
| } | ||
| is PsiField -> { | ||
| val containing = target.containingClass?.internalName | ||
| ?: return maybeShow("Could not get owner of field", e) | ||
| val text = "public $containing ${target.name}" | ||
| val text2 = text.replace("/",".").replace(" (","(") | ||
| copyToClipboard(editor, element, text2) | ||
| } | ||
| is PsiMethod -> { | ||
| val containing = target.containingClass?.internalName | ||
| ?: return maybeShow("Could not get owner of method", e) | ||
| val desc = target.descriptor ?: return maybeShow("Could not get descriptor of method", e) | ||
| val modifiedContaining = containing.replace("/","."); | ||
| val text = "public ${modifiedContaining} ${target.internalName}$desc" | ||
| copyToClipboard(editor, element, text) | ||
| } | ||
| else -> maybeShow("Invalid element", e) | ||
| } | ||
| } | ||
|
|
||
| private fun copyToClipboard(editor: Editor?, element: PsiElement, text: String) { | ||
| val stringSelection = StringSelection(text) | ||
| val clpbrd = Toolkit.getDefaultToolkit().systemClipboard | ||
| clpbrd.setContents(stringSelection, null) | ||
| if (editor != null) { | ||
| showSuccessBalloon(editor, element, "Copied: \"$text\"") | ||
| } | ||
| } | ||
|
|
||
| private fun maybeShow(text: String, e: AnActionEvent?) { | ||
| if (e != null) { | ||
| showBalloon(text, e) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't bump the version in PRs