Looking for some guidence

Hello,

My plugin is parsing annotations and depending on their placement and content the plugin will add/change code in the editor. For instance adding getters and setters when there is a @Get and/or @Set annotation. I want this to be reasonably "live" so that the user don't have to do anything. The code should just appear automatically when the user adds the annotation.

I know how to listen for changes both in the Document and PsiTree, however I want to make this a bit more performant and scalable. So, I'm looking for a way to recognize changes and basically batch the creation/alteration of the methods. The batch should then be executed when convenient, say every 1000 ms or maybe when the user stopped typing. Sort of like when you reparse the code in IDEA.

Is there a fitting class/manager that handles this already?

I would like to use whatever framework you already have in place in IDEA, since it would be wasteful to create a new one for something that you probably already have.

Any pointers would be appreciated.

Cheers,
Mikael Grev

3 comments
Comment actions Permalink

Hello Mikael,

In general we don't have many features which modify code automatically and
asynchonously ("Optimize imports on the fly" is the only one I can remember).
It would be more IDEA-like to hook into the typed handler and perform the
generation as the user edits the annotation (for example, when Enter is pressed).

If you do want to perform the generation in the background, one way you can
try is to provide an implementation of TextEditorHighlightingPassFactory
and TextEditorHighlightingPass, and perform the generation in the applyInformationToEditor()
method.

My plugin is parsing annotations and depending on their placement and
content the plugin will add/change code in the editor. For instance
adding getters and setters when there is a @Get and/or @Set
annotation. I want this to be reasonably "live" so that the user don't
have to do anything. The code should just appear automatically when
the user adds the annotation.

I know how to listen for changes both in the Document and PsiTree,
however I want to make this a bit more performant and scalable. So,
I'm looking for a way to recognize changes and basically batch the
creation/alteration of the methods. The batch should then be executed
when convenient, say every 1000 ms or maybe when the user stopped
typing. Sort of like when you reparse the code in IDEA.

Is there a fitting class/manager that handles this already?

I would like to use whatever framework you already have in place in
IDEA, since it would be wasteful to create a new one for something
that you probably already have.

Any pointers would be appreciated.


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


0
Comment actions Permalink

Thanks Dmitry, much appreciated.


Btw, PsiAnnotation.getQualifiedName() seems to be very slow. About 100ms the first time and then around 10ms. To me that sounds very heavy. The file it is in is very very small.

Also, time to add a new code element to the PsiClass (e.g. a method) has trippled between IDEA 7 and 8. It also feels kind of slow compared to what it does.

I have a quite fast computer with 4GB of memory (OS X).

Cheers,
Mikael

0
Comment actions Permalink

Hello Mikael,

Thanks Dmitry, much appreciated.

Btw, PsiAnnotation.getQualifiedName() seems to be very slow. About
100ms the first time and then around 10ms. To me that sounds very
heavy. The file it is in is very very small.


It doesn't matter how large the file is. getQualifiedName() performs resolve,
so it can be slow.

Also, time to add a new code element to the PsiClass (e.g. a method)
has trippled between IDEA 7 and 8. It also feels kind of slow compared
to what it does.


If you have CPU snapshots for these operations taken on IDEA 7 and IDEA 8,
we'll be happy to look at them.

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


0

Please sign in to leave a comment.