Getting latest AST

SyntaxEditor for WPF Forum

Posted 6 years ago by Daisuke Nakada
Version: 17.2.0660
Avatar

Hello,

I have 2 questions about the AST.

1:

I need to get the latest AST every time just after an end user types "if[ENTER_KEY]" to support auto-indent function.

But the SyntaxEditor.Document.ParseData.Ast is not always the latest when "NotifyDocumentTextChanged" callback is called.

So, please tell me how to get the latest AST when "IEditorDocumentTextChangeEventSink.NotifyDocumentTextChanged" callback is called.

Is it OK to call SyntaxLanguageParsingExtensions' "Parse" method every time "NotifyDocumentTextChanged" is called?

Or is there a better way to achieve this?

My current code is like below;

void IEditorDocumentTextChangeEventSink.NotifyDocumentTextChanged(SyntaxEditor editor, EditorSnapshotChangedEventArgs e) {
	if (e.TextChange.Type != TextChangeTypes.Enter) {
		return;
	}
        ...
	ILLParseData parseData = (ILLParseData) editor.Document.Language.Parse(e.NewSnapshot.Text); 
	...
}

 

2:

The documentation "Walkthrough: Callbacks and Error Handling" says, "An Error node is inserted when a non-terminal fails to match.."

I tried QuickStarts "4c - Error Handling" and input invalid text there but "Document Outline" pane did not show any "Error" node.

Are there any other conditions that are not written on the documentation in order to have an "Error" node?

Comments (2)

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

Hello,

1) That is correct, when the ambient parse request dispatcher is configured, the parser will run in a worker thread after any document text change.  This is the recommended configuration.  The downside of that is that the parser will lag behind a tad since it's occurring asynchronously.  For small documents, this lag will be minimal.  For larger documents, it could take a second or two (or more) depending on the document size.

While you could turn off the ambient parse request dispatcher to disable async parsing, that is not recommended because it will cause the parsing to occur in the UI thread, and that can severely affect editing performance.

The dispatcher has a WaitForParse method you can call where you pass the parse hash key to wait for and how long max to wait.  You can get the parse hash key via a call to the static ParseRequest.GetParseHashKey method.

The other thing to note is that the parse results have a snapshot associated with them.  So for instance in our .NET Languages Add-on, any time we have to access the AST, we use snapshot translation to determine how the offsets in the old AST have possibly been affected and get them updated in terms of the current snapshot.

2) I apologize about the documentation on the "Error" node.  We used to have that functionality but pulled it out at one point when we added the capability to support type-specifc AST nodes.  With those, we could no longer add a generic Error node to them so we had to abandon that functionality.  Honestly it wasn't that useful anyhow.  We are going to correct the documentation for the upcoming maintenance release.


Actipro Software Support

Posted 6 years ago by Daisuke Nakada
Avatar

Thank you very much.

Then, I will read tokens instead of using the AST when ENTER_KEY is typed in order to determine whether auto-indent is needed.

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.