monaco-editor: SetModelMarkers shows "Undefined" as error message

Hi, I am using “setModelMarkers()” to highlight the syntax errors in Monaco editor for my custom language. The message added to the marker is not getting displayed on hovering over the highlighted text.

{
                code: null, 
                source: null,
                severity: 3,
                startLineNumber: 1,
                startColumn: 1,
                endLineNumber: 1,
                endColumn: 4 + 1,
                message: 'Syntax error\n'
 }

The message always shows as “undefined”. image Please let me know if any thing is missed or done wrong.

monaco-editor version: 0.11.1 Browser: Chrome OS: win 7

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I have similar “undefined” issue with a bit different steps but I think root cause is the same.

This example from monaco playground when running from Angular 5 application produces “undefined” when you hover over warning on enum value, other warnings like “Missing property XXX” are affected too.

Issue is happening when signalInnerHTML is executed which triggers Promise.all resolving above it.

But the issue is actually on Angular’s Zone.js side as it re-defines promises. It has to be fixed in Promise.all definition, index/count mismatch is happening in monaco-editor case.

The only workaround I have for now is by redefining Promise.all with a fix locally (e.g. within polyfills.ts)

Promise.all = function (values: any): Promise<any> {
    let resolve: (v: any) => void;
    let reject: (v: any) => void;
    let promise = new this((res, rej) => {
      resolve = res;
      reject = rej;
    });
    let count = 0;
    let index = 0;
    const resolvedValues: any[] = [];
    for (let value of values) {
      if (!(value && value.then)) {
        value = this.resolve(value);
      }
      value.then(
          ((index) => (value: any) => {
            resolvedValues[index] = value;
            count--;
            if (!count) {
                resolve(resolvedValues);
            }
          })(index),
          reject);
      count++;
      index++;
    }
    if (!count) resolve(resolvedValues);
    return promise;
}

This works fine for me:

var ed = monaco.editor.create(document.getElementById("container"), {
	value: "function hello() {\n\talert('Hello world!');\n}",
	language: "javascript"
});

monaco.editor.setModelMarkers(ed.getModel(), 'test', [{
    startLineNumber: 2,
    startColumn: 1,
    endLineNumber: 2,
    endColumn: 1000,
    message: "a message",
    severity: monaco.Severity.Warning
}])

image

@jrieken I see that removal of WinJS.Promise is an epic you’re working on. Would you be open to a PR fixing this issue specifically? Changing MarkdownRenderer.getOptions’ codeBlockRenderer to return a native promise? Or perhaps ModeServiceImpl._onReady to use Promise.resolve(true) instead of WinJS.Promise.as(true) ?

@taras-mytofir . Can you suggest a solution to work around this ? . I am using monaco-edtior version 0.13 with angular 5 and face the same issue