Generate Data-Structure of PsiFile for Annotator once before 'annotate' is called for every element
Hi!
I'm currently attempting to create a simple plugin extending the already existing JSON language. I've already got a json schema, but that's not really enough to support things like auto complete (e.g. I have a property where the value would get vaölidated based on a totally different property value somewhere different in the file).
I'm using an com.intellij.lang.annotation.Annotator, where it's obviously called for every PsiElement - but I would need to traverse the whole PsiFile to find those values which are allowed for the annotated PsiElement. That would happen for every single PsiElement, is there any possibility, like a PreAnnotateFile-Method to collect those values beforehand? Otherwise it would be quite a few .parent.parent.parent.parent…. and child searching.
Example JSON:
{
"my-values": {
"test1": {
"id": "my-id1"
},
"test2": {
"id": "my-id2"
}
},
"my-other-things:" {
"whatever": {
"reference": "only my-id1 or my-id2 is allowed (and should be auto-completed)"
}
}
}
Please sign in to leave a comment.
You can cache expensive calculations based on the contents of the current file using `CachedValue` https://plugins.jetbrains.com/docs/intellij/psi-performance.html#cache-results-of-heavy-computations.
Yann Cebron That sounds exactly like what I need - will try that out. Thank you!