Hello, I've not found API for force validate editor content. It's necessary for me to catch moment when validation is completed and call some methods based on actual editor state. How can i do it?
P.S.
If I add listener to change model content :
editor.onDidChangeModelContent(function (e) {
monaco.editor.getModelMarkers({});
});
I cannot get actual error state, bacause validation by diagnostic options is not completed.
You could have a look at the following event https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.icodeeditor.html#ondidchangemodeldecorations. Maybe that helps.
@spahnke , Hello, thanks, it works, but this event calls for several times (for content change, for validation), may be you know, how to understand when an event is called for validation?
A decoration always has an owner; in case of JavaScript/TypeScript validation this is the string "javascript"/"typescript", respectively, and conincides with the language (or modeId). If you implement the validation yourself, you get to specify the owner.
This can be used to only get those decorations that come from a specific owner, like this:
editor.onDidChangeModelDecorations(() => {
const model = this.editor.getModel();
if (model === null || model.getModeId() !== "javascript")
return;
const owner = model.getModeId();
const markers = monaco.editor.getModelMarkers({ owner });
// do something with the markers
});
In case of syntax validation for JavaScript/TypeScript, those decorations should mostly be validation errors, though I'm not 100% sure.
Most helpful comment
A decoration always has an
owner; in case of JavaScript/TypeScript validation this is the string"javascript"/"typescript", respectively, and conincides with the language (ormodeId). If you implement the validation yourself, you get to specify the owner.This can be used to only get those decorations that come from a specific owner, like this:
In case of syntax validation for JavaScript/TypeScript, those decorations should mostly be validation errors, though I'm not 100% sure.