use*_*624 4 code-editor ace-editor
我正在使用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"
}]);
Run Code Online (Sandbox Code Playgroud)
您可以使用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