6

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

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

现在的问题是ACE如何在某个位置显示错误

4

2 回答 2

10

您可以使用注释来显示错误。编辑器装订线显示错误甚至警告或带有错误消息的信息。

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"
}]);
于 2017-02-08T19:57:26.297 回答
2

您可以使用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

于 2013-08-31T08:08:27.190 回答