DocumentListener.documentChanged(): PsiFile isn't updated

I have added the DocumentListener and update information in the tool window on document change (like outline view for the current file).
The problem is when I access the current PsiFile in the documentChanged() method then PsiFile doen't contain recent changes.

Do I need different listener type (something for listening PSI changes)? Should I use inspections for this task? Or there is method to update PSI caches?

2 comments

Hello Alex,

I have added the DocumentListener and update information in the tool
window on document change (like outline view for the current file).

The problem is when I access the current PsiFile in the
documentChanged() method then PsiFile doen't contain recent changes.

Do I need different listener type (something for listening PSI
changes)? Should I use inspections for this task? Or there is method
to update PSI caches?


You should call PsiDocumentManager.getInstance().commitDocument() before
accessing the PSI from your documentChanged() handler.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0


"Dmitry Jemerov" <yole@jetbrains.com> wrote in message
news:431b0f66617e18c9eaac2242cfc6@news.jetbrains.com...

Hello Alex,

>
>> I have added the DocumentListener and update information in the tool
>> window on document change (like outline view for the current file).
>>
>> The problem is when I access the current PsiFile in the
>> documentChanged() method then PsiFile doen't contain recent changes.
>>
>> Do I need different listener type (something for listening PSI
>> changes)? Should I use inspections for this task? Or there is method
>> to update PSI caches?
>

You should call PsiDocumentManager.getInstance().commitDocument() before
accessing the PSI from your documentChanged() handler.

>

And generally you won't do this anyway, since calling commitDocument() on
every document change will slow down everything.
If you are tracking PSI changes you should rather
PsiManager.addPsiChangeListener().


--
regards,
Alexey Kudravtsev
Software Developer
JetBrains, Inc, http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.