PsiSearchHelper - findFilesWithPlainTextWords not working

Hi,

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 

TEMPLATE

{

  @A,

  @B

}

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?

Thanks

Marco

3 comments
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?

 

Thanks

Marco

0

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.

0

Please sign in to leave a comment.