PsiSearchHelper - findFilesWithPlainTextWords not working


I'm trying to find all files that contains a specific word, like "TEMPLATE".

This is my code:


final PsiSearchHelper helper = PsiSearchHelper.getInstance(project);
PsiFile[] pfs = helper.findFilesWithPlainTextWords("TEMPLATE");



The content of one of my files is 






The problem is that the result is an empty array.

I checked on debug the helper object and the DumpService state is "SMART" so if I understood correctly it means index is built and ready to use.

What am I doing wrong?



Official comment

The problem is that this method returns only "plain text" occurrences, and yous is probably "code". You could try calling methods from CacheManager and pass a bit mask there composed of the flavors you need (declared in UsageSearchContext class)

Thanks Peter, I understand what you are saying.


I probably omitted an important info, I'm trying to search inside my custom language files and it looks like both PsiSearchHelper and CacheManager work only on txt (so far I can match words only in these files), but I could not find anything on my custom language files, even with UsageSearchContext.IN_CODE.

Do I have to implement some kind of class/interface for this in order to work?





It depends on how those identifiers are classified during indexing. This is usually done by WordsScanner implementation for your language, most likely it's DefaultWordsScanner. You can put a breakpoint there, type in your file and then see which tokens with which usage search contexts are returned.


Please sign in to leave a comment.