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

Commit

Permalink
Merge pull request #357 from aminya/lazy-debug
Browse files Browse the repository at this point in the history
Add enableDebug to config
  • Loading branch information
sadick254 committed Dec 16, 2020
2 parents 70e021e + 4874154 commit 071a3c0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/locale-checker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const spellchecker = require('spellchecker');
const pathspec = require('atom-pathspec');
const env = require('./checker-env');
const debug = require('debug');

// The locale checker is a checker that takes a locale string (`en-US`) and
// optionally a path and then checks it.
Expand All @@ -22,7 +21,12 @@ class LocaleChecker {
this.enabled = true;
this.hasSystemChecker = hasSystemChecker;
this.inferredLocale = inferredLocale;
this.log = debug('spell-check:locale-checker').extend(locale);
if (atom.config.get('spell-check.enableDebug')) {
debug = require('debug');
this.log = debug('spell-check:locale-checker').extend(locale);
} else {
this.log = (str) => {};
}
this.log(
'enabled',
this.isEnabled(),
Expand Down
9 changes: 7 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const { CompositeDisposable } = require('atom');
const debug = require('debug');

let SpellCheckView = null;
let spellCheckViews = {};

const LARGE_FILE_SIZE = 2 * 1024 * 1024;

let log = (str) => {};

module.exports = {
activate() {
const log = debug('spell-check');
if (atom.config.get('spell-check.enableDebug')) {
debug = require('debug');
log = debug('spell-check');
}

log('initializing');

this.subs = new CompositeDisposable();
Expand Down
8 changes: 6 additions & 2 deletions lib/spell-check-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const debug = require('debug');
const env = require('./checker-env');

class SpellCheckerManager {
Expand Down Expand Up @@ -424,7 +423,12 @@ class SpellCheckerManager {

init() {
// Set up logging.
this.log = debug('spell-check:spell-check-manager');
if (atom.config.get('spell-check.enableDebug')) {
debug = require('debug');
this.log = debug('spell-check:spell-check-manager');
} else {
this.log = (str) => {};
}

// Set up the system checker.
const hasSystemChecker = this.useSystem && env.isSystemSupported();
Expand Down
8 changes: 6 additions & 2 deletions lib/system-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ let instance;
const spellchecker = require('spellchecker');
const pathspec = require('atom-pathspec');
const env = require('./checker-env');
const debug = require('debug');

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

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
"description": "Display notices only on the console"
}
]
},
"enableDebug": {
"type": "boolean",
"default": false,
"title": "Enable debug information for spell check",
"order": 10
}
},
"consumedServices": {
Expand Down

0 comments on commit 071a3c0

Please sign in to comment.