Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting errors from Monaco editor

I would like to get hold of the errors created by default by Monaco editor.

enter image description here

like image 716
user2058239 Avatar asked Jun 09 '26 04:06

user2058239


2 Answers

It looks like you can call monaco.editor.getModelMarkers({}) to get the list of all markers in the document, and then filter that yourself to limit it to the errors you're interested in. I would prefer a more clearly-documented route, but in my ad-hoc testing this works.

like image 108
ehdv Avatar answered Jun 11 '26 19:06

ehdv


This is a simple sample to log errors:

import * as monaco from 'monaco-editor'

// ...

monaco.editor.onDidChangeMarkers(([uri]) => {
  const markers = monaco.editor.getModelMarkers({resource: uri})
  console.log('markers:', markers.map(
    ({ message, startLineNumber, startColumn, endLineNumber, endColumn }) =>
      `${message} [${startLineNumber}:${startColumn}-${endLineNumber}:${endColumn}]`,
  ))
})
like image 25
Mir-Ismaili Avatar answered Jun 11 '26 19:06

Mir-Ismaili



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!