Caret should be positioned at symbol to be renamed Follow
Trying to write my first plugin I am trying to rename the identifier at the caret in a java file using the builtin RenameProcessor.
I then systematically get the same error message
"Cannot perform refactoring"
"Caret should be positioned at symbol to be renamed".
The caret is positioned correctly and the identifier can be renamed from the Refactor/Rename... menu item.
I have seen a similar error reported by different users with different languages (at least JSon) but no solution posted yet.
I am running Community 2022.2.4
Please sign in to leave a comment.
I suggest debugging:
in both cases: renaming from your action and from the Refactor | Rename and compare what is missing in your case. It's hard to guess what the reason is with the information you provided.
Thank you Karol Lewandowski. Indeed debugging seems the way to go.
Could you please share the reason and solution to help others who face the same in the future?
Sorry about my phrasing. I meant that the idea of debugging seems reasonable: not that it has actually worked yet. But of course, if I find the reason I will post it.
I have set a breakpoint at the line you linked.
hasRenameProcessor is false
hasWritableMetaData is false
element is an instance of PsiIdentifierImpl and does not seem to be an (indrect) instance of PsiNamedElement
ChatGPT4 has found the bug. Instead of an element a namedElement is needed as suggested by the condition you pointed at Karol Lewandowski, thanks.
This line must be added after the initialization of element and of course namedElement must be used the in stead of element.