I would like to detect errors in real-time. Based on recommendations in ControlValueAccessor - string concatenation, I avoid calling toString until I definitely need the value.
I could detect value changes, call toString and use a function like this to catching syntax errors:
Yes, if you iterate through the the syntax tree for nodes marked as errors, that could give you the location of parse errors, though it doesn’t provide you with any error message or anything like that.
Thanks. This is proving more difficult than I thought it would be. I’ve got the tree and a cursor to iterate over it. But it’s not clear how a SyntaxNode is marked as having an error.
// cm is EditorView
const tree: Tree = syntaxTree(cm.state);
const cursor: TreeCursor = this.tree.cursor();
while (cursor.next()) {
const sn: SyntaxNode = cursor.node;
const nt: NodeType = sn.type;
if (nt.isError) {
// syntax error!
}
}
Ugh. Apologies. I was only getting the syntax tree in the constructor, and not on each call to validate the form control. It’s all working. Thanks for your support. I’ll update the public repo with this.