suren-atoyan / monaco-loader

The utility to easy setup monaco-editor into your browser
MIT License
177 stars 37 forks source link

getModelMarkers() or onDidChangeMarkers() are not exist #46

Open SSlippa opened 4 months ago

SSlippa commented 4 months ago

I am trying to get makers to have some aside validation but somehow it does not exist on the editor object. However, it exists in the editor API, any solution or explanation would be useful Using @monaco-editor/loader v 1.4.0

Thanks

suren-atoyan commented 3 months ago

could you please share a code snippet, I want to see how you try to get getModelMarkers()

SSlippa commented 3 months ago

@suren-atoyan sure, as you see here, only onDidChangeModelContent() event is working as expected I have tried different ways, but if I check what is inside the object, those methods do not exist

loader.init().then((monaco: Monaco) => {
      this.monacoEditor = monaco.editor.create(this.editorElement.nativeElement, {
        value: this.cssString,
        language: 'css',
        theme: 'vs',
      });

      this.monacoEditor.onDidChangeModelContent(() => {
        // HERE IT WORKS
      });

      this.monacoEditor.getModelMarkers(() => {
        // DOES NOT WORK
      });

      this.monacoEditor.onDidChangeMarkers(() => {
        // DOES NOT WORK
      });
    });

UPDATE: Found a way, how it supposed to work

this.monacoEditor.editor.onDidChangeMarkers(() => {
       // We have to provide an owner to getModelMarkers(), that is doing a job
        const updatedMarkers = monaco.editor.getModelMarkers({ owner: 'css' });
        console.log('Updated markers:', updatedMarkers);
      });