-
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 all 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,42 @@ 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", []); | ||
|
||
// 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", true); | ||
|
||
/** | ||
* Check whether any of code hints preferences for JS Code Hints is disabled | ||
* @return {boolean} enabled/disabled | ||
*/ | ||
function _areHintsEnabled() { | ||
return (PreferencesManager.get("codehint.JSHints") !== false) && | ||
(PreferencesManager.get("showCodeHints") !== false); | ||
} | ||
|
||
PreferencesManager.on("change", "codehint.JSHints", function () { | ||
jsHintsEnabled = _areHintsEnabled(); | ||
}); | ||
|
||
PreferencesManager.on("change", "showCodeHints", function () { | ||
jsHintsEnabled = _areHintsEnabled(); | ||
}); | ||
|
||
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. | ||
|
@@ -586,6 +608,10 @@ define(function (require, exports, module) { | |
// always clean up cached scope and hint info | ||
resetCachedHintContext(); | ||
|
||
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 |
||
if (editor && HintUtils.isSupportedLanguage(LanguageManager.getLanguageForPath(editor.document.file.fullPath).getId())) { | ||
initializeSession(editor, previousEditor); | ||
$(editor) | ||
|
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 code never gets the preferences to initialize
jsHintsEnabled
. This only gets set correctly when pref is changed.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.
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
definePreference
on line 68. But I can see that you want the other way around. I'm fine to hard-codetrue
for the 3rd param todefinePreference
. Then if we ever want to flip the default, we have to update these two places at the same time.