Skip to content

Commit

Permalink
Defer/reduce post-activate lint to reduce CPU load (fixes #67).
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Apr 6, 2019
1 parent c8f264a commit 33c2e4a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function getCustomRules () {
"' (" + (ex.message || ex.toString()) + ").");
}
});
lintVisibleFiles();
cleanLintVisibleFiles();
}
});
}
Expand Down Expand Up @@ -401,18 +401,18 @@ function fixLine (range, ruleName) {
});
}

// Lint all visible files
function lintVisibleFiles () {
// Cleanly (i.e., from scratch) lint all visible files
function cleanLintVisibleFiles () {
diagnosticCollection.clear();
vscode.window.visibleTextEditors.forEach((textEditor) => lint(textEditor.document));
didChangeVisibleTextEditors(vscode.window.visibleTextEditors);
}

// Clears the map of custom configuration files and re-lints files
function clearConfigMap (eventUri) {
outputLine("INFO: Resetting configuration cache due to '" + configFileGlob + "' or setting change.");
configMap = {};
if (eventUri) {
lintVisibleFiles();
cleanLintVisibleFiles();
}
}

Expand Down Expand Up @@ -488,7 +488,7 @@ function didChangeConfiguration () {
clearRunMap();
clearCustomRules();
clearIgnores();
lintVisibleFiles();
cleanLintVisibleFiles();
}

function activate (context) {
Expand Down Expand Up @@ -530,8 +530,10 @@ function activate (context) {
fileSystemWatcher.onDidDelete(clearConfigMap)
);

// Lint already-visible files
lintVisibleFiles();
// Request (deferred) lint of active document
if (vscode.window.activeTextEditor) {
requestLint(vscode.window.activeTextEditor.document);
}
}

exports.activate = activate;

0 comments on commit 33c2e4a

Please sign in to comment.