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

问题描述 投票:4回答:2

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

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

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

ace-editor code-editor
2个回答
7
投票

您可以使用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"
}]);

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

© www.soinside.com 2019 - 2024. All rights reserved.