How do I react to PSI Tree changes?

Hi,

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?  

0
Avatar
Permanently deleted user

Hello, Konstantin.

For PSI tree changes you can try to use

PsiManager.addPsiTreeChangeListener(PsiTreeChangeListener listener)


Platform has an adapter for PsiTreeChangeListener -- PsiTreeChangeAdapter.

Hope, it will help you.

0

As I mentioned before, the correct API for caching resolve results is ResolveCache. It takes care of invalidating cached results on PSI change automatically.

0

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?

0

ResolveCache is invalidated on any change in the PSI tree anywhere.

0

Correct place for cache access would be implementation of PsiReferenceProvider?

0

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.

0

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:

   private ResolveCache getCache() {

        Project project = SharedImplUtil.getContainingFile(this.getXmlElement().getNode()).getProject();
        return ResolveCache.getInstance(project);

    }

0

请先登录再写评论。