Skip to content

incremental parsing

nbros edited this page Sep 13, 2010 · 3 revisions

The source code is fully parsed a first time.
Then each time it is modified, it needs to be re-parsed.
Re-parsing happens after a 500ms delay after the last keystroke, or immediately if completion is triggered. This makes it especially important that re-parsing is fast, so that the completion box doesn’t take too long to pop up (should be <100ms ideally).

To speed things up, re-parsing can be done incrementally: determine a “damage region”, re-parse it and inject the resulting AST node into the existing AST. This implies that the parser has several entry points.
The damage region could be found by following all modifications to the underlying document in Eclipse and matching the modification offsets with those of a top-level element in the previous AST. For example, if a function is modified, only the function is re-parsed (this function could be in a module).

This method will likely not produce a perfect result in every case, especially since the O’Caml syntax makes it difficult to know when a function ends (when it doesn’t end in “;;”). So, a full parse is always done on save, so that everything always behaves correctly on a saved.
Additionally, a key shortcut (eg. “F5”) could trigger a full parse.

Clone this wiki locally