javascript - Monaco editor - linting errors customization with warningerror icons - Stack Overflow

I've been previously using CodeMirror editor in my project, but recently I have decided to switch

I've been previously using CodeMirror editor in my project, but recently I have decided to switch to Monaco editor.

Now I am trying to provide my users with all the functionalities they had previously (+ additional ones provided by Monaco), and therefore I would like to provide them with similar way of showing linting warnings/errors.

Is there some way to achieve CodeMirror like way of showing errors, with use of icons in Monaco editor?

I've been previously using CodeMirror editor in my project, but recently I have decided to switch to Monaco editor.

Now I am trying to provide my users with all the functionalities they had previously (+ additional ones provided by Monaco), and therefore I would like to provide them with similar way of showing linting warnings/errors.

Is there some way to achieve CodeMirror like way of showing errors, with use of icons in Monaco editor?

Share Improve this question asked Jul 26, 2018 at 13:38 mkapiczymkapiczy 3413 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Ok, I've figured it out.

First I get the errors through some external source (I use JSHINT). Then I modify the decoration:

let newDecorations = errors.map(e => {
      return {
        range: new monaco.Range(e.startLineNumber, 1, e.startLineNumber, 1),
        options: {
          glyphMarginClassName: e.severity === monaco.Severity.Error ? 'errorIcon' : 'warningIcon',
          glyphMarginHoverMessage: {value: e.message}
        }
      }
    })

    this.decorations = this.editor.deltaDecorations(this.decorations, newDecorations)

The classes errorIcon, and warningIcon:

 .warningIcon {
  display: block;
  background-image: url('../assets/icons/warningIcon.png');
  background-size: contain;
  background-repeat: no-repeat;
}

.errorIcon {
  display: block;
  background-image: url('../assets/icons/errorIcon.png');
  background-size: contain;
  background-repeat: no-repeat;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744394148a4572055.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信