Why is the parser being triggered for every Return stroke?

I have implemented a parser which is very expensive in terms of processor load,
it takes about one second to parse a normal sized file (e.g. up to one hundred rows)....

Normally the parser is triggered only in idle typing times, and one second is pretty acceptable for this.

Nevertheless, in case of "Enter" key, the parser is triggered for every hit, and this makes editing the file quite annoying.
If pressed and hold, several overlapping parser threads are triggered... which I do not find ok.
Is this meant to be so? Does anyone have an idea on this?

4 comments
Comment actions Permalink

Hello Dan,

DC> I have implemented a parser which is very expensive in terms of
DC> processor load, it takes about one second to parse a normal sized
DC> file (e.g. up to one hundred rows)....
DC>
DC> Normally the parser is triggered only in idle typing times, and one
DC> second is pretty acceptable for this.
DC>
DC> Nevertheless, in case of "Enter" key, the parser is triggered for
DC> every hit, and this makes editing the file quite annoying.
DC>
DC> If pressed and hold, several overlapping parser threads are
DC> triggered… which I do not find ok.
DC>
DC> Is this meant to be so? Does anyone have an idea on this?

Yes, this is meant to be so. When Enter is pressed, the formatter is invoked
in order to indent the new line properly, and building the formatting model
requires parsing the file.

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


0
Comment actions Permalink

If that's totally unacceptable by your plugin you can try to overload
Enter operation for your files.

0
Comment actions Permalink

Thanks Dmitry, makes sense...

Yet! Usually the Enter keystroke is affecting only one whitespace PsiElement.
Why does it need to build the whole Psi tree again for this?

On the other hand you may say: "make your parser faster!" well... that's not so easy..

To follow the hint of Mike (btw. thanks Mike!), how can I find out within the parse() method, which event (keystroke) triggered the parser?
Completely overloading Enter is a bit too intrusive for me :-)..

0
Comment actions Permalink

To come back on this, is there a way to define root PsiBlocks which trigger the parser only for the given section in the document, when the edit operation takes place within this block? This would considerably speed up editing for large files. Not to mention that not all the identifiers in the file have to be resolved again. In case of a file with several thousands of rows, it would really make sense to parse only a certain section in this file for indenting and formatting purposes.

0

Please sign in to leave a comment.