Hi,
As I am using my custom language I get some underlines shown in the editor suggesting that errors found in code. How to see them or display all errors related to the script validation based on grammar?
I found only one property related to this topic: ErrorDisplayMode
Hello Tomas,
I am attaching a code-snippet that demonstrates how to get all of the errors in a XamSyntaxEditor at a particular time below. This code-snippet is from our WPF Samples Browser that you can install with the product, and it creates a full-document snapshot of the editor and uses the document’s SyntaxTree.RootNode.GetDiagnostics method to create a list of a “SyntaxErrorInfo” class internal to the samples browser to hold information about the errors. I hope this helps.
TextDocument doc = this.xamSyntaxEditor1.Document; // create a text span of the whole document TextSpan ts = new TextSpan(0, doc.CurrentSnapshot.Length); // obtain errors from the whole document IEnumerable<NodeDiagnostic> diagnostics = doc.SyntaxTree.RootNode.GetDiagnostics(ts); List<SyntaxErrorInfo> list = new List<SyntaxErrorInfo>(); SyntaxErrorInfo seInfo; foreach (NodeDiagnostic diagnostic in diagnostics) { // Obtain the location of the error SnapshotSpan span = diagnostic.SnapshotSpan; TextLocation location = span.Snapshot.LocationFromOffset(span.Offset); // Create an info object and set message, location and snapshot span seInfo = new SyntaxErrorInfo() { Message = diagnostic.Message, Line = location.Line + 1, Character = location.Character + 1, Span = diagnostic.SnapshotSpan }; // Add the error in the list list.Add(seInfo); }
Please let me know if you have any other questions or concerns on this matter.