-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Simple code hints preferences to enable/disable individual/all code hints providers. #8272
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,20 +48,39 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code never gets the preferences to initialize There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we're initializing the default value regardless of whether the prefs are available or not. This is why I use it on the 3rd param to |
||
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", []); | ||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 3rd param to |
||
|
||
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"); | ||
} | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is not quite right.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both of these prefs have default values, so this statement is not correct, but there is no UI so user needs to manually set values, so it's still a good idea to compare that returned value is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @redmunds Thanks for the code. You're right that I forgot to consider the cases where either of the prefs is not set. |
||
/** | ||
* 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; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should check this after |
||
// always clean up cached scope and hint info | ||
resetCachedHintContext(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3rd param to
definePreference
is the default value, so this should be hard-coded totrue
.