Change: use editorWorker.metalint

This commit is contained in:
eight 2018-10-01 22:49:16 +08:00
parent 5778d5c858
commit f47d57aea8

View File

@ -1,4 +1,4 @@
/* global linter */
/* global linter editorWorker */
'use strict';
function createMetaCompiler(cm) {
@ -18,25 +18,23 @@ function createMetaCompiler(cm) {
if (match[0] === meta && match.index === metaIndex) {
return cache;
}
return API.parseUsercss({sourceCode: match[0], metaOnly: true})
.then(result => result.usercssData)
.then(result => {
for (const cb of updateListeners) {
cb(result);
return editorWorker.metalint(match[0])
.then(({metadata, errors}) => {
if (!errors.length) {
for (const cb of updateListeners) {
cb(metadata);
}
}
cache = errors.map(err =>
({
from: cm.posFromIndex((err.index || 0) + match.index),
to: cm.posFromIndex((err.index || 0) + match.index),
message: err.message,
severity: err.code === 'unknownMeta' ? 'warning' : 'error'
})
);
meta = match[0];
metaIndex = match.index;
cache = [];
return cache;
}, err => {
meta = match[0];
metaIndex = match.index;
cache = [{
from: cm.posFromIndex((err.index || 0) + match.index),
to: cm.posFromIndex((err.index || 0) + match.index),
message: err.message,
severity: 'error'
}];
return cache;
});
});