It is again about the Mathematica Plugin (GitHub page) and I try to highlight nested levels of local variables. In this answer Dmitry said, that third-party plugins should use the Annotator extension in preference to HighlightingVisitor. Let me give two small examples of what I try to achieve:
Module and Block are both scoping constructs to localize variables. As you see, var1 gets shadowed by the inner Block which is perfectly fine. Module variables get different colors than Block variables and therefore the inner var1 should be colorized as Block-variable. Second example
Here, the argument to the function f which is defined is var. This var gets shadowed by the local Module var which is not fine and therefore the var in Module should be colorized as error.
Therefore, my Annotator has two requirements:
- It needs to annotate the code traversing top-down the PsiTree. This could be implemented by checking whether the PsiElement in com.intellij.lang.annotation.Annotator#annotate is the root file node and then annotating in a recursive manner. The question is, when I type code, does IDEA call the annotate function only for the chaged parts of the PsiTree? Are there other options?
- I need to store information on my recursive descent namely: Which variable are already defined in outer constructs.
Any help, hints or code-links are highly appriciated!