How do I react to PSI Tree changes? 关注
ok, I managed to create PSI reference , my DOM modell is purring and the next question is - how do I react to changes?
I would like to be informed of changes in certain PSI / DOM node to invalidate cached references
Is project service good place to store cached information?
For PSI tree changes you can try to use
Platform has an adapter for PsiTreeChangeListener -- PsiTreeChangeAdapter.
Hope, it will help you.
As I mentioned before, the correct API for caching resolve results is ResolveCache. It takes care of invalidating cached results on PSI change automatically.
OK, slowly grokking it.
Say, I'm implementing some DOM implementation which caches
intersting data obtained from subtags. It stores result on ResolveCache, using underlying XML tag as key
( which is PSI element ) - then it will be invalidated upon changes in subelements?
ResolveCache is invalidated on any change in the PSI tree anywhere.
Correct place for cache access would be implementation of PsiReferenceProvider?
No, it needs to be accessed from PsiReference.resolve(). ResolveCache has plenty of usages in the CE source code, you can look for examples there.
OK, getting it. Key would be reference itself and values are candidates. But in my case creating list of candidates is best
done in DOM model ( as this lst of candidates can be reused by several references) - so I would like to cache it also there
say: talk with resolve cache from DOM Element, initiated by reference in context of this element
Is it possible to keep a link to resolve cache in DOM element, or shall I retrieve it each time with: