CM6 marker to linenumber

Hello everyone,

I am very new to CodeMirror and am struggling with the markers. What I want to archive are error and warning messages like here in CM6:
https://codemirror.net/demo/lint.html

I am building a json schema validator and want to show error messages myself so I am looking for a function to add a marker to a specific line number. Could someone help?

Thanks
Alex

You could take a look at the @codemirror/lint extension’s implementation. Or possibly even use that directly.

Hi @marijn,

thanks for the quick hint. I checked out lint and if you have the “start” and “end” of the error this is very convenient to use. That is what I used for testing:

function validationErrorMarker(view) {
  let diagnostics = [];
  diagnostics.push({
    from: 70, to: 76,
    severity: "error",
    message: `Invalid type. Expected Integer, Null but got String.`
  });
  return diagnostics
}

let json_editor = new EditorView({
  state: EditorState.create({
    doc: '',
    extensions: [
      basicSetup,
      json(),
      updateListenerExtension,
      linter(validationErrorMarker),
      lintGutter()
    ]
  }),
  parent: document.getElementById('json')
})

However I only know the line number and the red dot would would be just enough.

I went through the code of lintGutter but wasn’t able to understand where the marker is added to the side. Can you help?

Thanks
Alex