PSI changes listener question

Hi,
Does anyone know is it possible to watch for specific PSI element type appearance right after it occured? PsiTreeChangeListener seems not fit for this. For example I want to watch for line comment element appearance.

Thanks,
Dmitry

8 comments

Hello Dmitry,

DK> Does anyone know is it possible to watch for specific PSI element
DK> type appearance right after it occured? PsiTreeChangeListener seems
DK> not fit for this. For example I want to watch for line comment
DK> element appearance.

First of all, PSI elements appear only when the PSI is committed. If the
user did a lot of typing without pauses, a lot of changes will be reported
to the PSI listener in one big batch.

Second, the PSI events have become much more granular in Demetra. If the
only thing the user typed was a line comment, you will receive an event telling
you that a line comment was added to a particular parent node. In earlier
versions, this would have been reported as a single "PSI for file changed"
event, and there was no way to receive more granular events.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

No, there is no such API, and I doubt it will ever be implemented due to performance issues (we would have to traverse the whole element added, firing events with every subelement)

0

Hi,
So PsiTreeChangeListener notified only by fact of document comitting but not useful info may be retrieved?

Thanks,
Dmitry

0

Thanks for the tip on Demetra changes.

0

Hello Dmitry,

DK> So PsiTreeChangeListener notified only by fact of document comitting
DK> but not useful info may be retrieved?

You won't get a separate event for every single added subelement (which is
what Eugene meant), but you can traverse the element returned by event.getNewChild()
to search for elements which are interesting for you.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hello Dmitry,

Hello Dmitry,

DK> So PsiTreeChangeListener notified only by fact of
document comitting
DK> but not useful info may be retrieved?

You won't get a separate event for every single added
subelement (which is
what Eugene meant), but you can traverse the element
returned by event.getNewChild()
to search for elements which are interesting for you.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


I asked cause newChild and oldChild both contains new children :( At least so in 5.1.2

Thanks,
Dmitry

0

Hi Eugene,
I wonder how much slowdown may cause
PsiElement[] psiElements = PsiTreeUtil.collectElements(event.getFile(), new PsiElementFilter() ...

invoked on beforeChildrenChange and childrenChanged of each PsiTreeChangeListener invocation to compare interested elements diff.

Thanks,
Dmitry

0

Hi Eugene,
I wonder how much slowdown may cause
PsiElement[] psiElements = PsiTreeUtil.collectElements(event.getFile(), new PsiElementFilter() ...

invoked on beforeChildrenChange and childrenChanged of each PsiTreeChangeListener invocation to compare interested elements diff.

Thanks,
Dmitry

0

Please sign in to leave a comment.