参考文档: - https://github.com/ajaxorg/ace/wiki/Syntax-validation 我根据上面的doc将createWorker方法添加到自定义模式,并将worker-example.js包含在同一个文件中并调用require(" ace / config")。set(" workerPath&#模式定义中的34;," ace / mode")
目前,workerPath没有被解雇,我看到了#34; GET http://localhost:3000/ace/mode/worker-example.js 404(未找到)"控制台出错。
这是我的自定义代码index.html.erb:
define('ace/mode/example-custom', [], function(require, exports, module) {
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var ExampleHighlightRules = require("ace/mode/example_highlight_rules").ExampleHighlightRules;
var WorkerClient = require("ace/worker/worker_client").WorkerClient;
require("ace/config").set("workerPath", "ace/mode");
var Mode = function() {
this.HighlightRules = ExampleHighlightRules;
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "--";
this.blockComment = {start: "->", end: "<-"};
this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], workerpath, "WorkerExample");
worker.attachToDocument(session.getDocument());
console.log("worker", worker);
worker.on("errors", function(e) {
session.setAnnotations(e.data);
});
worker.on("annotate", function(results) {
session.setAnnotations(results.data);
});
worker.on("terminate", function() {
session.clearAnnotations();
});
return worker;
};
define('ace/mode/worker-example', [], function(require, exports, module) {
var oop = require("ace/lib/oop");
var Mirror = require("ace/worker/mirror").Mirror;
var WorkerExample = exports.WorkerExample = function(sender) {
Mirror.call(this, sender);
this.setTimeout(200);
};
oop.inherits(WorkerExample, Mirror);
(function() {
this.onUpdate = function() {
var lines = editor.session.doc.getAllLines();
var errors = [];
for (var i = 0; i < lines.length; i++){
if (/[\w\d{(['"]/.test(lines[i])) {
alert("hello");
errors.push({
row: i,
column: lines[i].length,
text: "Missing Semicolon",
type: "error"
});
}
}
this.sender.emit("annotate", errors);
};
}).call(WorkerExample.prototype);
});