如何在ace编辑器中添加警告或错误通知



我使用ACE编辑器进行交互式python编辑,同时我在后端有一个python解释器,它将把python代码解析为结果。

当用户将代码提交到后端时,python解析器会将代码解析为结果,如果发生错误,它会返回行和列,以及JSON格式中的错误描述

现在的问题是ACE如何在特定位置显示错误

您可以使用Annotations来显示错误。编辑器槽显示错误,甚至显示带有错误消息的警告或信息。

var editor = ace.edit("editor");
editor.getSession().setAnnotations([{
  row: 1,
  column: 0,
  text: "Error Message", // Or the Json reply from the parser 
  type: "error" // also "warning" and "information"
}]);

您可以使用editor.session.addMarker(Range, classname, type)并添加一些css,例如.classname{position:absolute; border-bottom: 1px solid green}

要获得一个很好的示例,请参阅https://github.com/c9/core/blob/a256cf12a06c8d18bd45f8797a23c507b313ab65/plugins/c9.ide.language.core/marker.js#L139

最新更新