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

View File

@ -191,13 +191,24 @@ function updateLinter({immediately} = {}) {
} }
function updateLintReport(cm, delay) { 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) { if (delay === 0) {
// immediately show pending csslint/stylelint messages in onbeforeunload and save // immediately show pending csslint/stylelint messages in onbeforeunload and save
clearTimeout(state.lintTimeout);
update(cm); update(cm);
return; return;
} }
if (delay > 0) { if (delay > 0) {
setTimeout(cm => { clearTimeout(state.lintTimeout);
state.lintTimeout = setTimeout(cm => {
if (cm.performLint) { if (cm.performLint) {
cm.performLint(); cm.performLint();
update(cm); update(cm);
@ -205,15 +216,10 @@ function updateLintReport(cm, delay) {
}, delay, cm); }, delay, cm);
return; 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) // 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 // or update it as soon as possible (default: 500ms lint + 100ms) in case an existing issue was just fixed
clearTimeout(state.reportTimeout); 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; state.postponeNewIssues = delay === undefined || delay === null;
function update(cm) { function update(cm) {
@ -251,19 +257,18 @@ function updateLintReport(cm, delay) {
}).join('') + '</tbody>'; }).join('') + '</tbody>';
scopedState.markedLast = newMarkers; scopedState.markedLast = newMarkers;
fixedOldIssues |= scopedState.reportDisplayed && Object.keys(oldMarkers).length > 0; fixedOldIssues |= scopedState.reportDisplayed && Object.keys(oldMarkers).length > 0;
if (scopedState.html !== html) { if ((scopedState.html || '') !== html) {
scopedState.html = html; scopedState.html = html;
changed = true; changed = true;
} }
}); });
if (changed) { if (changed) {
clearTimeout(state ? state.renderTimeout : undefined); 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); renderLintReport(true);
} else { } else {
state.renderTimeout = setTimeout(() => { state.renderTimeout = setTimeout(renderLintReport, CodeMirror.defaults.lintReportDelay, true);
renderLintReport(true);
}, CodeMirror.defaults.lintReportDelay);
} }
} }
} }