0

I have added the error markers using setModelMarkers when i had invalid dtaa on validation of the content of a yaml comtent displayed in monocoeditor? But how to remove that error markes if we have valid data on the editor?

monaco.editor.onDidCreateModel(function(model) {
    function validate() {
      var textToValidate = model.getValue();

      // return a list of markers indicating errors to display

      // replace the below with your actual validation code which will build
      // the proper list of markers

      var markers = [{
        severity: monaco.MarkerSeverity.Error,
        startLineNumber: 1,
        startColumn: 2,
        endLineNumber: 1,
        endColumn: 5,
        message: 'hi there'
      }];

      // change mySpecialLanguage to whatever your language id is
      monaco.editor.setModelMarkers(model, 'mySpecialLanguage', markers);
    }

    var handle = null;
    model.onDidChangeContent(() => {
      // debounce
      clearTimeout(handle);
      handle = setTimeout(() => validate(), 500);
    });
    validate();
});

// -- below this is the original canned example code:

// Register a new language

Taken the reference from here. Syntax validation of a custom language in Monaco editor Can anyone help?

1 Answers1

0

I don't know if it is still needed, but anyway you can try just rewriting markers with an empty array.

monaco.editor.setModelMarkers(model, 'mySpecialLanguage', []);
Lanzz
  • 1
  • 1