當然有。快速瀏覽最後一個版本的remoting-lint.js(https://github.com/marijnh/CodeMirror/commit/27f097ed75561e846bdb955f13f8dd2bcf0b589e)的內容顯示它僅僅是一個jQuery AJAX請求,它調用提供給該函數的回調作爲參數。這個回調只會在lint插件提供「async」選項的情況下通過。請注意,我有一些選項被傳遞到CodeMirror中,這些選項可能與您無關。棉絨相關的選項是「排水溝」和「lintWith」。
請注意,Python一次只顯示一個錯誤,但lint插件接受錯誤列表。因爲前者,後者最多隻會有一件物品。
function python_validator(cm, updateLinting, options) {
var text = cm.getValue() + "\n";
if(text.trim() == "")
{
updateLinting(cm, []);
return;
}
function result_cb(error)
{
var found = [];
if(error != null) {
var start_line = error.line_no;
var start_char = error.column_no;
var end_line = error.line_no;
var end_char = error.column_no;
var message = error.message;
found.push({
from: CodeMirror.Pos(start_line - 1, start_char),
to: CodeMirror.Pos(end_line - 1, end_char),
message: message
});
}
updateLinting(cm, found);
}
check_python_syntax(text, result_cb)
};
var text_obj = $discriminator_text.get()[0];
var editor = CodeMirror.fromTextArea(text_obj, {
mode: { name: "python",
version: 2,
singleLineStringErrors: false },
lineNumbers: true,
indentUnit: 4,
tabMode: "shift",
matchBrackets: true,
styleActiveLine: true,
lineWrapping: false,
gutters: ["CodeMirror-lint-markers"],
lintWith: {
"getAnnotations": python_validator,
"async" : true,
},
});
我已經發布了一個非常簡單的項目,使這個多一點簡單:https://github.com/dsoprea/CodeMirrorRemoteValidator
好放,一爲您分享知識的意願(回答了你自己的職位)和額外的努力發佈github項目。 –
這就是它的全部內容。 –