Parsing problem

SyntaxEditor for WPF Forum

Posted 4 years ago by Eyal Lefler
Version: 15.1.0624


We are using you syntax editor and we encountered the following problem :

We created a class that implements IEditorDocumentTextChanged.

In the NotifyDocumentTextChanged, we open a completion session if the last tokens are assignment+whitespace or equality+whitespace.
Sometimes, when opening a completion session after typing == and whitespace, we get the session that is expected after typing = and whitespace.

In the CompletionProvider.RequestSession function the View.CurrentSapshot.Text contains ==, but the View.CurrentSapshot.Document.ParseData.Ast is the ast I expext when assignment+whitespace are typed.

As I said it does not happen always - so parsing the same text gives different ASTs...

Do you have any idea what can be the cause of this problem ?



Comments (1)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Eyal,

Yes, the thing to keep in mind here is that the document snapshots and their text are always up to date.  However parsing (and thus AST generation) is done in a worker thread so that those relatively long operations don't cause a performance lag in the editor.  This means that at any given time, and most likely when text is being typed, the snapshot text will be current in NotifyDocumentTextChanged but the parse data will likely be "behind" and for another recent snapshot.  The parse data does tell you which snapshot number it's for.

What we generally do in our add-ons that works well is if we are examining a line, we assume that everything from the caret back to the start of the current statement is in flux and likely being edited by the user.  We only use the snapshot text to examine that portion.  Then beyond that, we translate the offset of the statement start to the snapshot used to build the AST and examine the AST at that point.  This assumes that the containing AST nodes of the statement are still relatively accurate.

Hope that helps!

Actipro Software Support

The latest build of this product (v2020.1.1) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.