question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getModelMarker() doesn't include newly introduced Markers

See original GitHub issue

Describe the bug Using getModelMarkers() when handling the onChange event of ControlledEditor does not include any ModelMarkers that were introduced by the change being handled.

It does, however, include any ModelMarkers that existed before the current change.

  const handleEditorChanged = (ev, value) => {
    const errors = monacoRef.current.editor.getModelMarkers();
    console.log(errors);
    // returns [] when first ModelMarker is introduced
  };

To Reproduce https://codesandbox.io/s/nifty-ardinghelli-7w84o

Expected behavior When called inside the ControlledEditor’s onChange handler, getModelMarkers() should include any ModelMarkers that were introduced by the change being handled.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome

Additional context I would also think this is possible without using the monaco instance, since I already have a ref for the editor itself (see codesandbox)… Please let me know if I’m just going about this all wrong 🙂

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
suren-atoyancommented, Jan 14, 2021

I examined the case; I reckon it won’t be “fixed”. I mean we call onacoRef.current.editor.getModelMarkers() right after content is changed, but monaco to understand are there any problems “need” time. The example @SakaSaiTrinath mentioned, works. I create a snippet based on that. There is also another method. Currently, I am planning a new major version release, and probably one of them I’ll use to provide something like onValidate, but for now you can use one of the versions mentioned above.

0reactions
SakaSaiTrinathcommented, Oct 14, 2020

monacoRef.current.editor.getModelMarkers() function returns the current markers but not the updated markers. So, you can’t use this function to track errors.

Instead this works well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

getModelMarker behavior inside editor ... - GitHub
Using getModelMarkers() when handling the onDidChangeModelContent event of editor does not include any ModelMarkers that were introduced by ...
Read more >
monaco editor - How to remove Model-Markers in MonacoEditor
As pointed out in the comments, getModelMarkers() returns an array of IMarker, which do not have a dispose() method.
Read more >
monaco-editor | Yarn - Package Manager
Introduction of IEditor.createDecorationsCollection API; New function removeAllMarkers to remove all markers; Support for light high contrast theme ...
Read more >
Building a code editor with Monaco - Expo Blog
I work on Snack, an online code editor for React Native apps. In the past, Snack's code editor used Ace Editor, but we've...
Read more >
View Raw - UNPKG
Type definitions for monaco-editor v0.18.0 * Released under the MIT ... of markers */ export function getModelMarkers(filter: { owner?: string; resource?:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found