-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
yaml_worker.js
53 lines (42 loc) · 1.43 KB
/
yaml_worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define(function(require, exports) {
"use strict";
var oop = require("../lib/oop");
var Mirror = require("../worker/mirror").Mirror;
var lint = require("./yaml/yaml-lint").lint;
var YamlWorker = exports.YamlWorker = function(sender) {
Mirror.call(this, sender);
this.setTimeout(500);
this.setOptions();
};
oop.inherits(YamlWorker, Mirror);
(function() {
this.setOptions = function() {
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.changeOptions = function(newOptions) {
oop.mixin(this.options, newOptions);
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.onUpdate = function() {
var _this = this;
var value = this.doc.getValue();
var errors = [];
lint(value, {}, function(error) {
if (!error) {
_this.sender.emit("annotate", errors);
return;
}
// error.mark is not always defined, if undefined we default to displaying the error at the top row of the document.
var markDefined = !!error.mark;
errors.push({
row: markDefined ? error.mark.line : 0,
column: markDefined ? error.mark.column : 0,
text: error.reason,
type: 'error',
raw: error
});
_this.sender.emit("annotate", errors);
});
};
}).call(YamlWorker.prototype);
});