Switch to new linter and worker

This commit is contained in:
eight 2018-08-31 20:01:39 +08:00
parent af08f1ae23
commit 873c0cff4b
3 changed files with 33 additions and 11 deletions

View File

@ -25,7 +25,7 @@
<script src="js/script-loader.js"></script> <script src="js/script-loader.js"></script>
<script src="js/storage-util.js"></script> <script src="js/storage-util.js"></script>
<script src="content/apply.js"></script> <script src="content/apply.js"></script>
<script src="edit/lint.js"></script> <!-- <script src="edit/lint.js"></script> -->
<script src="edit/util.js"></script> <script src="edit/util.js"></script>
<script src="edit/regexp-tester.js"></script> <script src="edit/regexp-tester.js"></script>
<script src="edit/applies-to-line-widget.js"></script> <script src="edit/applies-to-line-widget.js"></script>
@ -65,6 +65,8 @@
<script src="vendor/codemirror/addon/fold/comment-fold.js"></script> <script src="vendor/codemirror/addon/fold/comment-fold.js"></script>
<link href="vendor/codemirror/addon/lint/lint.css" rel="stylesheet" /> <link href="vendor/codemirror/addon/lint/lint.css" rel="stylesheet" />
<script src="vendor/codemirror/addon/lint/lint.js"></script>
<link href="vendor/codemirror/addon/hint/show-hint.css" rel="stylesheet" /> <link href="vendor/codemirror/addon/hint/show-hint.css" rel="stylesheet" />
<script src="vendor/codemirror/addon/hint/show-hint.js"></script> <script src="vendor/codemirror/addon/hint/show-hint.js"></script>
@ -87,6 +89,14 @@
<link href="edit/codemirror-default.css" rel="stylesheet"> <link href="edit/codemirror-default.css" rel="stylesheet">
<script src="edit/codemirror-default.js"></script> <script src="edit/codemirror-default.js"></script>
<script src="edit/linter.js"></script>
<script src="edit/linter-csslint.js"></script>
<script src="edit/linter-stylelint.js"></script>
<script src="edit/linter-meta.js"></script>
<script src="edit/linter-report.js"></script>
<script src="edit/editor-worker.js"></script>
<link id="cm-theme" rel="stylesheet"> <link id="cm-theme" rel="stylesheet">
<template data-id="appliesTo"> <template data-id="appliesTo">

View File

@ -1,5 +1,5 @@
/* /*
global CodeMirror linterConfig loadScript global CodeMirror loadScript
global editors editor styleId ownTabId global editors editor styleId ownTabId
global save toggleStyle setupAutocomplete makeSectionVisible getSectionForChild global save toggleStyle setupAutocomplete makeSectionVisible getSectionForChild
global getSectionsHashes global getSectionsHashes
@ -8,9 +8,6 @@ global messageBox
'use strict'; 'use strict';
onDOMscriptReady('/codemirror.js').then(() => { onDOMscriptReady('/codemirror.js').then(() => {
CodeMirror.defaults.lint = linterConfig.getForCodeMirror();
const COMMANDS = { const COMMANDS = {
save, save,
toggleStyle, toggleStyle,

View File

@ -1,10 +1,10 @@
/* /*
global editors styleId: true global editors styleId: true
global CodeMirror dirtyReporter global CodeMirror dirtyReporter
global updateLintReportIfEnabled initLint linterConfig updateLinter
global createAppliesToLineWidget messageBox global createAppliesToLineWidget messageBox
global sectionsToMozFormat global sectionsToMozFormat
global beforeUnload global beforeUnload
global createMetaCompiler linter
*/ */
'use strict'; 'use strict';
@ -44,7 +44,6 @@ function createSourceEditor(style) {
cm.on('changes', () => { cm.on('changes', () => {
dirty.modify('sourceGeneration', savedGeneration, cm.changeGeneration()); dirty.modify('sourceGeneration', savedGeneration, cm.changeGeneration());
updateLintReportIfEnabled(cm);
}); });
CodeMirror.commands.prevEditor = cm => nextPrevMozDocument(cm, -1); CodeMirror.commands.prevEditor = cm => nextPrevMozDocument(cm, -1);
@ -55,9 +54,17 @@ function createSourceEditor(style) {
cm.operation(initAppliesToLineWidget); cm.operation(initAppliesToLineWidget);
updateMeta().then(() => { const metaCompiler = createMetaCompiler(cm);
metaCompiler.onSuccess(meta => {
style.usercssData = meta;
style.name = meta.name;
style.url = meta.homepageURL;
updateMeta();
});
initLint(); linter.hook(cm);
updateMeta().then(() => {
let prevMode = NaN; let prevMode = NaN;
cm.on('optionChange', (cm, option) => { cm.on('optionChange', (cm, option) => {
@ -65,7 +72,7 @@ function createSourceEditor(style) {
const mode = getModeName(); const mode = getModeName();
if (mode === prevMode) return; if (mode === prevMode) return;
prevMode = mode; prevMode = mode;
updateLinter(); linter.refresh();
updateLinterSwitch(); updateLinterSwitch();
}); });
@ -88,7 +95,7 @@ function createSourceEditor(style) {
function updateLinterSwitch() { function updateLinterSwitch() {
const el = $('#editor.linter'); const el = $('#editor.linter');
el.value = linterConfig.getName(); el.value = getCurrentLinter();
const cssLintOption = $('[value="csslint"]', el); const cssLintOption = $('[value="csslint"]', el);
const mode = getModeName(); const mode = getModeName();
if (mode !== 'css') { if (mode !== 'css') {
@ -100,6 +107,14 @@ function createSourceEditor(style) {
} }
} }
function getCurrentLinter() {
const name = prefs.get('editor.linter');
if (cm.getOption('mode') === 'stylus' && name === 'csslint') {
return 'stylelint';
}
return name;
}
function setupNewStyle(style) { function setupNewStyle(style) {
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) + style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
`/* ${t('usercssReplaceTemplateSectionBody')} */`; `/* ${t('usercssReplaceTemplateSectionBody')} */`;