How to get Custom language elements to be treated as "text" for rename refactoring purposes?

Answered

In my markdown plugin I would like to have most language elements that contain text to be searched for rename refactoring references from other languages like Java. So that any references to Java classes and methods in the documentation would be found and refactored.

I implemented a custom FindUsagesProvider and use the DefaultWordsScanner implementation for the getWordsScanner() method.

I tried passing all relevant ElementTypes in the literalTokenSet, I tried passing an empty set for literalTokenSet. No difference. When I refactor in Java the markdown text elements are not presented as either text or literal locations.

What is the proper way to communicate to the IDE what elements in a custom language should be treated as either text or literal strings for purpose of refactoring done in another languages?

 

0
2 comments

Hi Vladimir,

if you have a reference from your code to java, then the text of the element under reference would be treated as "code", when there is no such a reference, the text would be treated as text or string literals. If text is string literal or not, the answer is given by custom language's com.intellij.lang.ParserDefinition (#getStringLiteralElements). Both cases are processed by com.intellij.refactoring.util.TextOccurrencesUtil#addTextOccurences/#addUsagesInStringsAndComments.

BTW I guess that you don't need to write custom usages provider for that, only if you want to find usages of your language.

Anna

0

Thanks Anna. I double checked and everything was already as you described.

The cause for not finding the text references was the fact that the markdown file and the refactored element were in different modules and the module containing the markdown file did not have the other module as its dependency.

Once I added the dependency, rename refactoring started to show the text/literal occurrences in markdown.

 

0

Please sign in to leave a comment.