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/storage-util.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/regexp-tester.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>
<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" />
<script src="vendor/codemirror/addon/hint/show-hint.js"></script>
@ -87,6 +89,14 @@
<link href="edit/codemirror-default.css" rel="stylesheet">
<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">
<template data-id="appliesTo">

View File

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

View File

@ -1,10 +1,10 @@
/*
global editors styleId: true
global CodeMirror dirtyReporter
global updateLintReportIfEnabled initLint linterConfig updateLinter
global createAppliesToLineWidget messageBox
global sectionsToMozFormat
global beforeUnload
global createMetaCompiler linter
*/
'use strict';
@ -44,7 +44,6 @@ function createSourceEditor(style) {
cm.on('changes', () => {
dirty.modify('sourceGeneration', savedGeneration, cm.changeGeneration());
updateLintReportIfEnabled(cm);
});
CodeMirror.commands.prevEditor = cm => nextPrevMozDocument(cm, -1);
@ -55,9 +54,17 @@ function createSourceEditor(style) {
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;
cm.on('optionChange', (cm, option) => {
@ -65,7 +72,7 @@ function createSourceEditor(style) {
const mode = getModeName();
if (mode === prevMode) return;
prevMode = mode;
updateLinter();
linter.refresh();
updateLinterSwitch();
});
@ -88,7 +95,7 @@ function createSourceEditor(style) {
function updateLinterSwitch() {
const el = $('#editor.linter');
el.value = linterConfig.getName();
el.value = getCurrentLinter();
const cssLintOption = $('[value="csslint"]', el);
const mode = getModeName();
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) {
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
`/* ${t('usercssReplaceTemplateSectionBody')} */`;