add jslint example
This commit is contained in:
parent
faa155a20f
commit
1e4ee57d63
6 changed files with 101 additions and 25 deletions
|
|
@ -59,7 +59,7 @@ exports.launch = function(env) {
|
||||||
var emacs = require("ace/keyboard/keybinding/emacs").Emacs;
|
var emacs = require("ace/keyboard/keybinding/emacs").Emacs;
|
||||||
var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
|
var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
|
||||||
|
|
||||||
var WorkerClient = require("ace/worker/WorkerClient").WorkerClient;
|
var WorkerClient = require("ace/worker/worker_client").WorkerClient;
|
||||||
|
|
||||||
var docs = {};
|
var docs = {};
|
||||||
|
|
||||||
|
|
@ -67,8 +67,36 @@ exports.launch = function(env) {
|
||||||
docs.js.setMode(new JavaScriptMode());
|
docs.js.setMode(new JavaScriptMode());
|
||||||
docs.js.setUndoManager(new UndoManager());
|
docs.js.setUndoManager(new UndoManager());
|
||||||
|
|
||||||
var worker = new WorkerClient("../..", ["ace", "pilot"], "ace/worker/demo", "Demo");
|
var worker = new WorkerClient("../..", ["ace", "pilot"], "ace/worker/mirror", "Mirror");
|
||||||
worker.send("juhu");
|
worker.call("setValue", [docs.js.getValue()]);
|
||||||
|
|
||||||
|
docs.js.getDocument().on("change", function(e) {
|
||||||
|
e.range = {
|
||||||
|
start: e.data.range.start,
|
||||||
|
end: e.data.range.end
|
||||||
|
};
|
||||||
|
worker.emit("change", e);
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.on("jslint", function(results) {
|
||||||
|
console.log("jslint", results);
|
||||||
|
|
||||||
|
var rows = [];
|
||||||
|
for (var i=0; i<results.data.length; i++) {
|
||||||
|
var error = results.data[i];
|
||||||
|
if (error)
|
||||||
|
rows.push(error.line-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
docs.js.clearBreakpoints();
|
||||||
|
docs.js.setBreakpoints(rows)
|
||||||
|
});
|
||||||
|
|
||||||
|
window.mirror = function() {
|
||||||
|
worker.call("getValue", [], function(value) {
|
||||||
|
console.log(value)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
docs.css = new EditSession(document.getElementById("csstext").innerHTML);
|
docs.css = new EditSession(document.getElementById("csstext").innerHTML);
|
||||||
docs.css.setMode(new CssMode());
|
docs.css.setMode(new CssMode());
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ace_gutter-cell.ace_breakpoint {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
.ace_editor .ace_sb {
|
.ace_editor .ace_sb {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,11 @@ var require = function(name) {
|
||||||
if (require.modules[name])
|
if (require.modules[name])
|
||||||
return require.modules[name].exports;
|
return require.modules[name].exports;
|
||||||
|
|
||||||
require.id = name;
|
|
||||||
|
|
||||||
var chunks = name.split("/");
|
var chunks = name.split("/");
|
||||||
chunks[0] = require.tlns[chunks[0]] || chunks[0];
|
chunks[0] = require.tlns[chunks[0]] || chunks[0];
|
||||||
path = require.baseUrl + "/" + chunks.join("/") + ".js"
|
path = require.baseUrl + "/" + chunks.join("/") + ".js"
|
||||||
|
|
||||||
|
require.id = name;
|
||||||
importScripts(path);
|
importScripts(path);
|
||||||
return require.modules[name].exports;
|
return require.modules[name].exports;
|
||||||
};
|
};
|
||||||
|
|
@ -28,12 +27,13 @@ var define = function(factory) {
|
||||||
var module = {
|
var module = {
|
||||||
exports: {}
|
exports: {}
|
||||||
};
|
};
|
||||||
var returnExports = factory(require, module.exports, module);
|
|
||||||
if (returnExports) {
|
|
||||||
module.exports = exports;
|
|
||||||
}
|
|
||||||
|
|
||||||
require.modules[require.id] = module;
|
var name = require.id;
|
||||||
|
var returnExports = factory(require, module.exports, module);
|
||||||
|
if (returnExports)
|
||||||
|
module.exports = exports;
|
||||||
|
|
||||||
|
require.modules[name] = module;
|
||||||
};
|
};
|
||||||
|
|
||||||
function initBaseUrls(baseUrl, topLevelNamespaces) {
|
function initBaseUrls(baseUrl, topLevelNamespaces) {
|
||||||
|
|
@ -60,7 +60,7 @@ function initSender() {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
this.event = function(name, data) {
|
this.emit = function(name, data) {
|
||||||
postMessage({
|
postMessage({
|
||||||
type: "event",
|
type: "event",
|
||||||
name: name,
|
name: name,
|
||||||
|
|
@ -85,6 +85,6 @@ onmessage = function(e) {
|
||||||
var clazz = require(msg.module)[msg.classname];
|
var clazz = require(msg.module)[msg.classname];
|
||||||
main = new clazz(sender);
|
main = new clazz(sender);
|
||||||
} else if (msg.event) {
|
} else if (msg.event) {
|
||||||
|
sender._dispatchEvent(msg.event, msg.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -276,8 +276,8 @@ SOFTWARE.
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
exports.lint = (function () {
|
var JSLINT = exports.JSLINT = (function () {
|
||||||
"use strict";
|
//"use strict";
|
||||||
|
|
||||||
var adsafe_id, // The widget's ADsafe id.
|
var adsafe_id, // The widget's ADsafe id.
|
||||||
adsafe_may, // The widget may load approved scripts.
|
adsafe_may, // The widget may load approved scripts.
|
||||||
|
|
@ -3820,9 +3820,9 @@ loop: for (;;) {
|
||||||
advance('(');
|
advance('(');
|
||||||
spaces(this, t);
|
spaces(this, t);
|
||||||
no_space();
|
no_space();
|
||||||
if (nexttoken.id === 'var') {
|
// if (nexttoken.id === 'var') {
|
||||||
error("Move all 'var' declarations to the top of the function.");
|
// error("Move all 'var' declarations to the top of the function.");
|
||||||
}
|
// }
|
||||||
if (peek(0).id === 'in') {
|
if (peek(0).id === 'in') {
|
||||||
v = nexttoken;
|
v = nexttoken;
|
||||||
switch (funct[v.value]) {
|
switch (funct[v.value]) {
|
||||||
|
|
|
||||||
38
lib/ace/worker/mirror.js
Normal file
38
lib/ace/worker/mirror.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
|
var Document = require("ace/document").Document;
|
||||||
|
var lint = require("ace/worker/jslint").JSLINT;
|
||||||
|
var lang = require("pilot/lang");
|
||||||
|
|
||||||
|
var Mirror = exports.Mirror = function(sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
var doc = this.doc = new Document("");
|
||||||
|
|
||||||
|
var deferredUpdate = this.deferredUpdate = lang.deferredCall(this.onUpdate.bind(this));
|
||||||
|
|
||||||
|
sender.on("change", function(e) {
|
||||||
|
doc.applyDeltas([e.data]);
|
||||||
|
deferredUpdate.schedule(500);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
this.setValue = function(value) {
|
||||||
|
this.doc.setValue(value);
|
||||||
|
this.deferredUpdate.schedule(500);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getValue = function(callbackId) {
|
||||||
|
this.sender.callback(this.doc.getValue(), callbackId);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onUpdate = function() {
|
||||||
|
lint(this.doc.getValue(), {undef: false, onevar: false, passfail: false});
|
||||||
|
this.sender.emit("jslint", lint.errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).call(Mirror.prototype);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -46,7 +46,7 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "event":
|
case "event":
|
||||||
_self.$dispatchEvent(msg.name, {data: msg.data});
|
_self._dispatchEvent(msg.name, {data: msg.data});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "call":
|
case "call":
|
||||||
|
|
@ -69,10 +69,16 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.call = function(cmd, args, callback) {
|
this.call = function(cmd, args, callback) {
|
||||||
|
if (callback) {
|
||||||
var id = this.callbackId++;
|
var id = this.callbackId++;
|
||||||
this.callbacks[id] = callback;
|
this.callbacks[id] = callback;
|
||||||
args.push(id);
|
args.push(id);
|
||||||
this.$send(cmd, args);
|
}
|
||||||
|
this.send(cmd, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.emit = function(event, data) {
|
||||||
|
this.$worker.postMessage({event: event, data: data});
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(WorkerClient.prototype);
|
}).call(WorkerClient.prototype);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue