show lint report on open earlier; lint on import

This commit is contained in:
tophf 2017-08-29 23:36:56 +03:00
parent 4c616442f6
commit 0189ae1d64
2 changed files with 29 additions and 27 deletions

View File

@ -1287,19 +1287,18 @@ function initWithStyle({style, codeIsUpdated}) {
updateTitle();
return;
}
// if this was done in response to an update, we need to clear existing sections
getSections().forEach(div => { div.remove(); });
const queue = style.sections.length ? style.sections.slice() : [{code: ''}];
const queueStart = new Date().getTime();
const t0 = performance.now();
// after 100ms the sections will be added asynchronously
while (new Date().getTime() - queueStart <= 100 && queue.length) {
while (performance.now() - t0 <= 100 && queue.length) {
add();
}
(function processQueue() {
if (queue.length) {
add();
setTimeout(processQueue, 0);
setTimeout(processQueue);
}
})();
initHooks();
@ -1307,12 +1306,8 @@ function initWithStyle({style, codeIsUpdated}) {
function add() {
const sectionDiv = addSection(null, queue.shift());
maximizeCodeHeight(sectionDiv, !queue.length);
const cm = sectionDiv.CodeMirror;
if (CodeMirror.lint) {
setTimeout(() => {
cm.setOption('lint', CodeMirror.defaults.lint);
updateLintReport(cm, 0);
}, prefs.get('editor.lintDelay'));
if (!queue.length) {
editors.last.state.renderLintReportNow = true;
}
}
}
@ -1451,9 +1446,9 @@ function validate() {
return null;
}
function updateLintReportIfEnabled(cm, time) {
if (CodeMirror.lint) {
updateLintReport(cm, time);
function updateLintReportIfEnabled(...args) {
if (CodeMirror.defaults.lint) {
updateLintReport(...args);
}
}
@ -1568,8 +1563,10 @@ function fromMozillaFormat() {
function doImport(event) {
// parserlib contained in CSSLint-worker.js
onDOMscripted(['vendor-overwrites/csslint/csslint-worker.js'])
.then(() => doImportWhenReady(event.target));
onDOMscripted(['vendor-overwrites/csslint/csslint-worker.js']).then(() => {
doImportWhenReady(event.target);
editors.last.state.renderLintReportNow = true;
});
}
function doImportWhenReady(target) {

View File

@ -191,13 +191,24 @@ function updateLinter({immediately} = {}) {
}
function updateLintReport(cm, delay) {
if (cm && !cm.options.lint) {
// add 'lint' option back to the freshly created section
setTimeout(() => {
if (!cm.options.lint) {
cm.setOption('lint', linterConfig.getForCodeMirror());
}
});
}
const state = cm && cm.state && cm.state.lint || {};
if (delay === 0) {
// immediately show pending csslint/stylelint messages in onbeforeunload and save
clearTimeout(state.lintTimeout);
update(cm);
return;
}
if (delay > 0) {
setTimeout(cm => {
clearTimeout(state.lintTimeout);
state.lintTimeout = setTimeout(cm => {
if (cm.performLint) {
cm.performLint();
update(cm);
@ -205,15 +216,10 @@ function updateLintReport(cm, delay) {
}, delay, cm);
return;
}
// eslint-disable-next-line no-var
var state = cm.state.lint;
if (!state) {
return;
}
// user is editing right now: postpone updating the report for the new issues (default: 500ms lint + 4500ms)
// or update it as soon as possible (default: 500ms lint + 100ms) in case an existing issue was just fixed
clearTimeout(state.reportTimeout);
state.reportTimeout = setTimeout(update, state.options.delay + 100, cm);
state.reportTimeout = setTimeout(update, (state.options || {}).delay + 100, cm);
state.postponeNewIssues = delay === undefined || delay === null;
function update(cm) {
@ -251,19 +257,18 @@ function updateLintReport(cm, delay) {
}).join('') + '</tbody>';
scopedState.markedLast = newMarkers;
fixedOldIssues |= scopedState.reportDisplayed && Object.keys(oldMarkers).length > 0;
if (scopedState.html !== html) {
if ((scopedState.html || '') !== html) {
scopedState.html = html;
changed = true;
}
});
if (changed) {
clearTimeout(state ? state.renderTimeout : undefined);
if (!state || !state.postponeNewIssues || fixedOldIssues) {
if (!state || !state.postponeNewIssues || fixedOldIssues || editors.last.state.renderLintReportNow) {
editors.last.state.renderLintReportNow = false;
renderLintReport(true);
} else {
state.renderTimeout = setTimeout(() => {
renderLintReport(true);
}, CodeMirror.defaults.lintReportDelay);
state.renderTimeout = setTimeout(renderLintReport, CodeMirror.defaults.lintReportDelay, true);
}
}
}