Explicitly control JS Hints provider with preferences for performance improvement.

This commit is contained in:
RaymondLim committed 2014-07-15 21:57:40 -07:00
1 parent 52e49ab7d3
commit 1e4d8e135a
2 files changed
+31 -11

No files matched your search

@@ -48,13 +48,15 @@ define(function (require, exports, module) {
Session = require("Session"),
Acorn = require("thirdparty/acorn/acorn");
var session = null, // object that encapsulates the current session state
cachedCursor = null, // last cursor of the current hinting session
cachedHints = null, // sorted hints for the current hinting session
cachedType = null, // describes the lookup type and the object context
cachedToken = null, // the token used in the current hinting session
matcher = null, // string matcher for hints
ignoreChange; // can ignore next "change" event if true;
var session = null, // object that encapsulates the current session state
cachedCursor = null, // last cursor of the current hinting session
cachedHints = null, // sorted hints for the current hinting session
cachedType = null, // describes the lookup type and the object context
cachedToken = null, // the token used in the current hinting session
matcher = null, // string matcher for hints
jsHintsEnabled = true, // preference setting to enable/disable the hint session
ignoreChange; // can ignore next "change" event if true;
// Define the defaultExclusions which are files that are known to cause Tern to run out of control.
PreferencesManager.definePreference("jscodehints.defaultExclusions", "array", []);
@@ -62,6 +64,23 @@ define(function (require, exports, module) {
// This preference controls when Tern will time out when trying to understand files
PreferencesManager.definePreference("jscodehints.inferenceTimeout", "number", 5000);
// This preference controls whether to create a session and process all JS files or not.
PreferencesManager.definePreference("codehint.JSHints", "boolean", jsHintsEnabled);
PreferencesManager.on("change", "codehint.JSHints", function () {
jsHintsEnabled = PreferencesManager.get("codehint.JSHints");
});
PreferencesManager.on("change", "showCodeHints", function () {
var showHintsEnabled = PreferencesManager.get("showCodeHints");
if (jsHintsEnabled && !showHintsEnabled) {
jsHintsEnabled = showHintsEnabled;
} else if (!jsHintsEnabled && showHintsEnabled) {
jsHintsEnabled = PreferencesManager.get("codehint.JSHints");
}
});
/**
* Sets the configuration, generally for testing/debugging use.
* Configuration keys are merged into the current configuration.
@@ -583,6 +602,10 @@ define(function (require, exports, module) {
* @param {Editor} previousEditor - the previous editor
*/
function installEditorListeners(editor, previousEditor) {
if (!jsHintsEnabled) {
return;
}
// always clean up cached scope and hint info
resetCachedHintContext();