Help with different behavior between writable and readonly files

I have a bug in my IdentifierHighlighter plugin when browsing read-only files that come from the JDK For example, if I do a Ctrl+N and bring up source code, my plugin doesn't really work that well. After debugging, it is because returns an empty collection. I copied the entire source file for from the and pasted it into a writable java file that was part of my project. My plugin worked perfectly and returned correct results.

Anybody know why I am getting different behavior with ReferencesSearch between a writable source file in my project and a readonly file from JDK
Does ReferencesSearch need the file to be writable or something?

Comment actions Permalink

I believe the problem is that the search doesn't work inside library sources rather than that it is related to read-only files.

The fix for this might be to use element, SearchScope searchScope) and specify something like "new LocalSearchScope(element.getContainingFile())" for the scope parameter.

Otherwise, when just using ReferencesSearch#search(PsiElement), you'll get GlobalSearchScope.projectScope(element.getProject()) as the search scope which doesn't include any libraries. The LocalSearchScope should could also be significantly faster, especially for public identifiers (fields, method).


Comment actions Permalink

Thanks a bunch. That was the answer. The plugin works great for files outside the current project.


Please sign in to leave a comment.