Highlight all usages

Hello,

I have a problem with my custom language, I'm trying to highlight usages of the element under the caret, but not all usages are highlighted. In the following code,

String foo;

fo<caret>o = "bar";


the first occurence of "foo" is correctly highlighted, but not the occurence under the caret. Ctrl-click leads me to the declaration, as expected, so resolve() seems to work okay.

The declaration PSI element implements PsiNameIdentifierOwner. Both occurences of "foo" are Identifier, which overrides getReference(). They resolve to the same declaration.

Any idea why the second foo is not highlighted?

Thanks

4 comments
Comment actions Permalink

Please check that PsiReference.isReferenceTo() is correctly implemented.

0
Comment actions Permalink

It is, at the moment I am using a naive "return element.equals(resolve());", but the thing is, this method is not called at all for these references... (it is called when highlighting type names, though).

0
Comment actions Permalink

Finally got it working: I forgot to override PsiNamedElement#getName() in the PSI class that's used for declarations.
Now every reference is correctly highlighted, and isReferenceTo() is called as well.

0
Comment actions Permalink

Thanks Past Me, I just had the same problem on another plugin and I'm glad I could help myself on this one ;)

1

Please sign in to leave a comment.