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": "foo.bar.Baz"
}


The PsiReference exists for the foo.bar.Baz part.

Unfortunately I am not able to get any hits with the PsiSearchHelper.
You can see my attempts here:
  https://github.com/defrac/defrac-plugin-intellij/blob/master/src/defrac/intellij/findUsages/MainClassReferencesSearch.java

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.


Best,
Joa
 

6 comments
Comment actions Permalink

Did you provide a ReferencesSearch implementation for your file type?


0
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?
0
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.

0
Comment actions Permalink

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

https://github.com/defrac/defrac-plugin-intellij/blob/master/src/defrac/intellij/findUsages/MainClassReferencesSearch.java

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.

0
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.

0
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.

0

Please sign in to leave a comment.