Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 071a3c0

Browse files
authored
Merge pull request #357 from aminya/lazy-debug
Add enableDebug to config
2 parents 70e021e + 4874154 commit 071a3c0

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

lib/locale-checker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const spellchecker = require('spellchecker');
22
const pathspec = require('atom-pathspec');
33
const env = require('./checker-env');
4-
const debug = require('debug');
54

65
// The locale checker is a checker that takes a locale string (`en-US`) and
76
// optionally a path and then checks it.
@@ -22,7 +21,12 @@ class LocaleChecker {
2221
this.enabled = true;
2322
this.hasSystemChecker = hasSystemChecker;
2423
this.inferredLocale = inferredLocale;
25-
this.log = debug('spell-check:locale-checker').extend(locale);
24+
if (atom.config.get('spell-check.enableDebug')) {
25+
debug = require('debug');
26+
this.log = debug('spell-check:locale-checker').extend(locale);
27+
} else {
28+
this.log = (str) => {};
29+
}
2630
this.log(
2731
'enabled',
2832
this.isEnabled(),

lib/main.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
const { CompositeDisposable } = require('atom');
2-
const debug = require('debug');
32

43
let SpellCheckView = null;
54
let spellCheckViews = {};
65

76
const LARGE_FILE_SIZE = 2 * 1024 * 1024;
87

8+
let log = (str) => {};
9+
910
module.exports = {
1011
activate() {
11-
const log = debug('spell-check');
12+
if (atom.config.get('spell-check.enableDebug')) {
13+
debug = require('debug');
14+
log = debug('spell-check');
15+
}
16+
1217
log('initializing');
1318

1419
this.subs = new CompositeDisposable();

lib/spell-check-manager.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const debug = require('debug');
21
const env = require('./checker-env');
32

43
class SpellCheckerManager {
@@ -424,7 +423,12 @@ class SpellCheckerManager {
424423

425424
init() {
426425
// Set up logging.
427-
this.log = debug('spell-check:spell-check-manager');
426+
if (atom.config.get('spell-check.enableDebug')) {
427+
debug = require('debug');
428+
this.log = debug('spell-check:spell-check-manager');
429+
} else {
430+
this.log = (str) => {};
431+
}
428432

429433
// Set up the system checker.
430434
const hasSystemChecker = this.useSystem && env.isSystemSupported();

lib/system-checker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ let instance;
22
const spellchecker = require('spellchecker');
33
const pathspec = require('atom-pathspec');
44
const env = require('./checker-env');
5-
const debug = require('debug');
65

76
// Initialize the global spell checker which can take some time. We also force
87
// the use of the system or operating system library instead of Hunspell.
@@ -24,7 +23,12 @@ if (env.isSystemSupported()) {
2423
// due to some memory bug.
2524
class SystemChecker {
2625
constructor() {
27-
this.log = debug('spell-check:system-checker');
26+
if (atom.config.get('spell-check.enableDebug')) {
27+
debug = require('debug');
28+
this.log = debug('spell-check:system-checker');
29+
} else {
30+
this.log = (str) => {};
31+
}
2832
this.log('enabled', this.isEnabled(), this.getStatus());
2933
}
3034

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
"description": "Display notices only on the console"
111111
}
112112
]
113+
},
114+
"enableDebug": {
115+
"type": "boolean",
116+
"default": false,
117+
"title": "Enable debug information for spell check",
118+
"order": 10
113119
}
114120
},
115121
"consumedServices": {

0 commit comments

Comments
 (0)