Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a warning or error notification to the ace editor

I'm using the ACE editor for interactive python editing, at the same time I have a python interpreter at the back end, which will parse the python code into results.

When the user submits the code to the backend, the python parser will parse the code into results, if errors happens, it will return the row and column, as well as the description of the error in JSON format

Now the problem is how can ACE display the error in certain position

like image 523
user824624 Avatar asked Aug 30 '13 13:08

user824624


2 Answers

You can use Annotations to display an error. The editors gutter shows the error and even warning or information with the error message.

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"
}]);
like image 94
Harsha pps Avatar answered Nov 17 '22 05:11

Harsha pps


You can use editor.session.addMarker(Range, classname, type) and add some css e.g. .classname{position:absolute; border-bottom: 1px solid green}

For a nice example of doing this see https://github.com/c9/core/blob/a256cf12a06c8d18bd45f8797a23c507b313ab65/plugins/c9.ide.language.core/marker.js#L139

like image 2
a user Avatar answered Nov 17 '22 07:11

a user