Ace editor - It doesn´t change the error window dynamically

136 views Asked by At

I have the next code:

var exeWindow = document.getElementById("exeWindow");
var errorWindow = document.getElementById("errorWindow");
var annot = editor.getSession().getAnnotations();
editor.getSession().on("changeAnnotation", execute);

function execute(){

        exeWindow.innerHTML = eval(editor.getValue());
        errorWindow.innerHTML = "";
        annot = editor.getSession().getAnnotations();

        for (var key in annot){
            if (annot.hasOwnProperty(key))
                console.log(annot[key].text + "on line " + " " + (parseInt(annot[key].row)+1));
                errorWindow.innerHTML = annot[key].text + " Line " + " " + (parseInt(annot[key].row)+1);
                exeWindow.innerHTML = "";
        }

        if (TogetherJS.running) {
            TogetherJS.send({type: "execute"});
        }
    };

Im trying to capture the error logs, and before execute a valid code works, but once I introduce for example 2+2, despite of exeWindow changes correctly, if a rewrite it to 2+a for example, searching a new error, the exeWindow doesn´t changes and the error does not appears in errorWindow.

EDIT: Sorry, the problem is that is not getting the correct errors, only the errors like 'missing semicolon'.

1

There are 1 answers

0
Raulvv On

If someone is interested, the solution I found is the next one:

function execute(){
try {
    exeWindow.innerHTML = eval(editor.getValue());
    errorWindow.innerHTML = "";
} catch(err){
    var annot = editor.getSession().getAnnotations();

    for (var key in annot){
        if (annot.hasOwnProperty(key)){
            errorWindow.innerHTML = annot[key].text + " Line " + " " + (parseInt(annot[key].row)+1);
            exeWindow.innerHTML = "";
        }
    }
}

if (TogetherJS.running) {
    TogetherJS.send({type: "execute"});
}

};

Simple as that :)