Ace: 有没有办法获得所有错误/警告?

创建于 2011-06-23  ·  5评论  ·  资料来源: ajaxorg/ace

我真的很喜欢在文本区域左侧的缓冲区中显示错误/警告图标的功能。 但是,我想获取所有错误/警告的集合,以便我可以在列表中向用户显示它们。 我还希望此集合包含行/列号,以便我可以将光标位置设置为每个问题。

我想要类似的东西:

var 错误 = editor.getSession().getErrors();
var (var i = 0; i < Errors.length; i ++)
{
var 错误 = 错误[i];
// 错误.行号
// 错误.ColumnNumber
// 错误.描述
}

最有用的评论

我为此在 Cloud9 中创建了一个插件,它称为 acebugs,它存在于此处:

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

我不知道您是在考虑扩展 cloud9 还是这是用于个人项目,但我想提一下,这样您就不会重复您的工作。 这是它的样子:

AceBugs in Cloud9

最好的,

马特

所有5条评论

数据称为annotations ,您可以通过以下调用检索它们:

editor.getSession().getAnnotations()

数据的结构如下:

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

感谢您及时的回复! 您能否提供一个关于如何访问为 getAnnotations 返回的对象的示例? 谢谢!

返回的对象只是散列的散列。 它看起来像这样:

this.$annotations = {};

因此 $annotations 哈希可能如下所示:

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

您可以像这样迭代响应:

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

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

我为此在 Cloud9 中创建了一个插件,它称为 acebugs,它存在于此处:

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

我不知道您是在考虑扩展 cloud9 还是这是用于个人项目,但我想提一下,这样您就不会重复您的工作。 这是它的样子:

AceBugs in Cloud9

最好的,

马特

马特,

感谢提供样品!

我已经玩过 Cloud9 了,但我仍然在寻找更多的个人项目。 正确的问题是我的另一个程序员在代码编辑器上工作了几个月,我认为使用这样的东西而不是重新发明轮子会更容易。

-麦克风

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

mkosieradzki picture mkosieradzki  ·  4评论

BoasE picture BoasE  ·  4评论

xfix picture xfix  ·  5评论

hojas picture hojas  ·  7评论

dimroc picture dimroc  ·  6评论