Use scope for ImplementationSearcher


I have succesfully implemented a definitionsScopeSearch that returns the implementations of specific PsiElements. I was trying to controle the SearchScope via the PsiElement.getUseScope on the element for which implementations are found. However, to my surprise this element is not used (directly) to determine the scope.

In: com.intellij.codeInsight.TargetElementUtil#getSearchScope, the search scope is retrieved from the containingFile if the element has a containing file and only if it has no containing file from the element itself. I don't understand why it would behave this way, why not use the getUseScope from the element but rather the file? 

For my specific situation I have a DSL where files can be referenced from other languages but the element only from my own language. This means that the getUseScope of the file is far too big when wanting to find implementations.

I could resolve this by providing 

public class MyOwnEvaluator extends TargetElementEvaluatorEx2 {

public @Nullable SearchScope getSearchScope(Editor editor,
@NotNull PsiElement element) {
return element.getUseScope();

Although this works and is a simple fix, I wonder if this isn't simply a bug in the design?

1 comment
Comment actions Permalink

This is actually the only current solution


Please sign in to leave a comment.