Rename behavior is different between editor and structure view
I implemented my own rename handler for certain tags in XML files. It works fine when I invoke it from the context menu in editor, but when I open the structure view and select Rename, it opens standard Rename XML Tag dialog even though I have my own rename dialog implemented. Is there any what to change that? I tried to run my plugin in the debugger, and it doesn't invoke my rename handler nor XmlTagRenameHandler, it goes straight to the PsiElementRernameHandler.
Please sign in to leave a comment.
Hi Eugene,
XmlTagRenameHandler doesn't work from structure view because it explicitly requires the editor (for the check com.intellij.xml.refactoring.XmlTagRenameHandler#isAvailableOnDataContext it tries to find element com.intellij.xml.refactoring.XmlTagRenameHandler#getElement from the editor). If your handler can work without an editor, it should know, how to retrieve an element from the DataContext and return true in isAvailableOnDataContext.
Hope this helps,
Anna
Thanks, Anna, that definitely helps, everything works fine now!
I have a follow up question though. Here's what I'm trying to do. I'm working on a plugin for Mule ESB and Mule ESB uses XML-based configuration files. Those files contain tags <flow>, each one has an attribute "name" with unique value. For example:
So renaming a <flow> tag actually means changing the value of the "name" attribute. That part already works fine, thanks to you for the suggestion.
Now, some <flow> tags may contain references to other flow tags, e.g.
and there can be many <flow-ref> tags pointing to the same flow.
Here's the problem - when I rename <flow-ref>, it does rename the flow it is pointing to. That's because I do have a FlowRefPsiReference which looks like this:
The problem I'm having is when I rename the <flow> tag, none of the <flow-ref> tags is renamed. In my FlowRenameHandler I get the flow tag and I call
bt it returns an empty collection. So my question is, what am I doing wrong (or not doing)?
Cool!
There are multiple things which could go wrong with references search. The common algorithm if you don't provide your own searcher:
1. find all textual occurrences in the scope (You need to check that the default effective scope of the search contains the file with the reference)
2. check if at position of that occurrence, there is a reference to the element to search
Most probably the problem is with resolve of the reference, the easiest way to debug starting from com.intellij.psi.PsiReference#isReferenceTo implementation.
Anna
@davidgreens