From 33c2e4aa5f7d7e14bc30b49917cee4c102ae90a8 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 6 Apr 2019 11:59:02 -0700 Subject: [PATCH] Defer/reduce post-activate lint to reduce CPU load (fixes #67). --- extension.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/extension.js b/extension.js index 89c6457..2f46949 100644 --- a/extension.js +++ b/extension.js @@ -246,7 +246,7 @@ function getCustomRules () { "' (" + (ex.message || ex.toString()) + ")."); } }); - lintVisibleFiles(); + cleanLintVisibleFiles(); } }); } @@ -401,10 +401,10 @@ 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 @@ -412,7 +412,7 @@ function clearConfigMap (eventUri) { outputLine("INFO: Resetting configuration cache due to '" + configFileGlob + "' or setting change."); configMap = {}; if (eventUri) { - lintVisibleFiles(); + cleanLintVisibleFiles(); } } @@ -488,7 +488,7 @@ function didChangeConfiguration () { clearRunMap(); clearCustomRules(); clearIgnores(); - lintVisibleFiles(); + cleanLintVisibleFiles(); } function activate (context) { @@ -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;