For our Mathematica Plug-in (open-source on GitHub) we finally wanted to tackle reference resolving. We have only one class which can act as reference: the implementation of the Symbol interface.
I adapted the example of the SimpleLanguage tutorial and made Symbol an extension to PsiNameIdentifierOwner, created a SymbolPsiReference extending PsiReferenceBase<Symbol> and implementing PsiPolyVariantReference and registered this in the plugin.xml.
Currently, the getVariants() method does nothing more than collecting all Symbols in the sourcefile. The problem is, it is never called and I suspect it is because my understanding of the psi-tree is flawed. Simple example:
As you can see the Symbol node wraps another PsiElement(IDENTIFIER). I initially wanted to make Symbol to be a psi-leaf because this represents the situation better but I was unable to do so. When I now type code, then
is invoked but the CompletionParameters contain PsiElement(IDENTIFIER) as myPosition and not the Symbol node.
Is this the problem and if yes, how can I fix it.