Ace: Is there a way to get all errors/warnings?

Created on 23 Jun 2011  ·  5Comments  ·  Source: ajaxorg/ace

I really like the feature that displays the error/warning icons in the buffer area to the left of the text area. However, I would like to get a collection of all errors/warnings so that I can display them to the user in a list. I would also like this collection to contain the line/column number so that I can set the cursor position to each issue.

I would like something like:

var Errors = editor.getSession().getErrors();
var (var i = 0; i < Errors.length; i ++)
{
var Error = Errors[i];
// Error.LineNumber
// Error.ColumnNumber
// Error.Description
}

Most helpful comment

I created a plugin for this purpose in Cloud9, it's called acebugs and it exists here:

https://github.com/ajaxorg/cloud9/blob/devel/client/ext/acebugs/acebugs.js

I didn't know if you were considering extending cloud9 or if this was for a personal project, but I wanted to mention it so you wouldn't duplicate your efforts. This is what it looks like:

AceBugs in Cloud9

Best,

Matt

All 5 comments

The data are called annotations and you can retrieve them with this call:

editor.getSession().getAnnotations()

The data is structured as such:

/**
 * Error:
 *  {
 *    row: 12,
 *    column: 2, //can be undefined
 *    text: "Missing argument",
 *    type: "error" // or "warning" or "info"
 *  }
 */

Thanks for the quick response! Could you please provide me an example on how to access the object that is returned for getAnnotations? Thanks!

The object returned is simply a hash of hashes. It looks like this:

this.$annotations = {};

Thus the $annotations hash might look like this:

{
    {
        row: 12,
        column: 2, //can be undefined
        text: "Missing argument",
        type: "error" // or "warning" or "info"
    },
    {
        row: 32,
        text: "Missing semicolon",
        type: "warning"
    },
    // etc
}

You can iterate over the response like so:

var annotations = editor.getSession().getAnnotations();

for (var anno in annotations) {
     // anno.row, anno.column, anno.text, anno.type
}

I created a plugin for this purpose in Cloud9, it's called acebugs and it exists here:

https://github.com/ajaxorg/cloud9/blob/devel/client/ext/acebugs/acebugs.js

I didn't know if you were considering extending cloud9 or if this was for a personal project, but I wanted to mention it so you wouldn't duplicate your efforts. This is what it looks like:

AceBugs in Cloud9

Best,

Matt

Matt,

Thanks for providing the samples!

I have played around with Cloud9 alittle but I am still looking for more of a personal project. The issue correctly being that my other programmer was working on a code editor for months and I figured that it would be easier to use something like this instead of reinventing the wheel.

-Mike

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SuperSajuuk picture SuperSajuuk  ·  4Comments

mkosieradzki picture mkosieradzki  ·  4Comments

STRd6 picture STRd6  ·  4Comments

mafar picture mafar  ·  4Comments

narraressan picture narraressan  ·  3Comments