From f47d57aea84af25f68a664e377a090eba949d472 Mon Sep 17 00:00:00 2001 From: eight Date: Mon, 1 Oct 2018 22:49:16 +0800 Subject: [PATCH] Change: use editorWorker.metalint --- edit/linter-meta.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/edit/linter-meta.js b/edit/linter-meta.js index 4233c402..a51f267c 100644 --- a/edit/linter-meta.js +++ b/edit/linter-meta.js @@ -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; }); });