Reference search scope different between project files and scratches?
Hi,
I'm trying to implement an inspection to tag unused symbols. See https://github.com/holgerbrandl/r4intellij/blob/master/src/com/r4intellij/inspections/UnusedVariableInspection.java#L72
For the implementation I do
Query<PsiReference> search = ReferencesSearch.search(element);
PsiReference first = search.findFirst();
if (first == null) {
... //handle the unused symbol
}
However, when working with the inspection, I've noticed that the search-scope seems to be different between project files (ie files under a module root) and scratch files (and also external files which were just dragged into Intellij). For the the former reference search is just performed across module files, and is thus blazingly fast. However, when applying the inspection to scratch files, the ReferencesSearch.search() also includes library sources (and not even just their stub-indices but the complete file content), which makes it super-slow.
Is this the intended behavior? If so, why are scratch-files treated differently (ie. using a different scope?
How can I match the scope from scratches to the one used for project-files?
Is there a scope to limit library reference search to just the stub-index elements?
Thanks,
Holger
Please sign in to leave a comment.
Hi Holger,
ReferencesSearch searches for usages inside element.getUseScope() (intersecting with provided scope when one is available). There are scope enlargers and the corresponding one is com.intellij.ide.scratch.ScratchFileServiceImpl#buildScratchesSearchScope (but not the library scope I hope). Could you please check what scope is constructed (com.intellij.psi.search.searches.ReferencesSearch.SearchParameters#getEffectiveSearchScope)? Looks like All scope (com.intellij.psi.search.ProjectScope#EVERYTHING_SCOPE_KEY) is united with your scope somewhere...
Thanks,
Anna