I am developing a language plugin where, for the sake of simplicity for this post, I only have functions and variables. It is easy enough for me to define in grammar that function declaration (by using keywords) should implement PsiNameIdentifierOwner and function calls are its references. I have implemented my own findUsagesProvider and as well as the go to declaration functionality works as expected.
I have to preface that I dont have control over the language itself (the language is MVEL).
I am lost as to how to handle variables, as their types can be interpreted. Example for the issue I am facing:
x = 1;
x = "string";
y = x;
With my current code all instance of variable x would implement PsiNameIdentifierOwner and when evoking the go to declaration, it would point to every other instance of variable x. But expected is that it should jump to x = 1;
So far it seems it would not be possible while defining the grammar (I am using Grammar-Kit) as its not distinguishable. It leads me to believe I have to process the whole tree after parsing and somehow and somewhere I have to add logic to define that the statement x = 1; PsiElement x should implement PsiNameIdentifierOwner. I am wondering if there is an expected way to handle such cases. By means of an extension or something else.