How to search for usages in custom file type?

I created a new FileType and also added references to Java classes for certain ranges.
When running a usage search, I'd like to show those usages too.

The usage looks like this:

    "main": ""

The PsiReference exists for the part.

Unfortunately I am not able to get any hits with the PsiSearchHelper.
You can see my attempts here:

I tried the following methods with both fully qualified name and just the name:
- processAllFilesWithWord
- processUsagesInNonJavaFiles
- processElementsWithWord

The GlobalSearchScopes I tried:
- GlobalSearchScope.allScope
- GlobalSearchScope.projectScope
- GlobalSearchScope.fileScope (with the file containing the reference)
- GlobalSearchScope.directoryScope

I do believe that some other problem must be involved? Maybe the file is simply not indexed?
Any guidance would be much appreciated.


Comment actions Permalink

Did you provide a ReferencesSearch implementation for your file type?

Comment actions Permalink

Quite possibly not. How do I do that?
I only provide the following:

<referencesSearch implementation="defrac.intellij.findUsages.MainClassReferencesSearch"/>

Can you tell me what kind of service/extension point I am looking for?
Comment actions Permalink

ReferencesSearch is the extension point that you need. If you have an implementation already, it should be called when you invoke the find usages operation.

Comment actions Permalink

Yes, I already implemented the ReferencesSearch and it gets executed.
This is the code I already have:

My problem is, that the PsiSearchHelper is never looking at the file -- since it is not source-code maybe?
It is basically a JSON file, at the top-level of the project, with a custom FileType.

As you can see in the code, I did a lot of different attempts but none of them was successful.
My question is how do I get the PsiSearchHelper to look into that file too?

Even when I create a GlobalSearchScope for that PsiFile, no work is performed by the PsiSearchHelper.

Comment actions Permalink

Ah, sorry, I missed that. Looks like you also need an indexer implementation. You can either provide an implementation of FindUsagesProvider with the getWordsScanner() method implemented, or provide an implementation of the idIndexer exension point.

Comment actions Permalink

Okay, thanks! But is that really the correct way to go forward? I think I must be doing something else wrong.

I just saw that you arleady have JsonFindUsagesProvider and the FileType I create extends LanguageFileType with JsonLanguage as its language.


Please sign in to leave a comment.