2013-08-30 48 views
0

我使用ACE編輯器進行交互式Python編輯,同時我在後端有一個python解釋器,它將python代碼解析爲結果。如何向ace編輯器添加警告或錯誤通知

當用戶提交代碼到後端,蟒蛇解析器將解析的代碼轉化爲成果,如果錯誤發生,它會返回的行和列,以及錯誤的JSON格式的描述

現在的問題是ACE如何在某個位置顯示錯誤

回答

2

您可以使用標註顯示錯誤。編輯器陰影顯示錯誤,甚至警告或錯誤信息。

var editor = ace.edit("editor"); 
editor.getSession().setMode("ace/mode/javascript"); 

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