Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
add pref to prevent js code hints on dot
Browse files Browse the repository at this point in the history
  • Loading branch information
redmunds committed Jul 20, 2014
1 parent 14cce3d commit e43a49f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/HintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ define(function (require, exports, module) {
* Determine if hints should be displayed for the given key.
*
* @param {string} key - key entered by the user
* @param {boolean} showOnDot - show hints on dot (".").
* @return {boolean} true if the hints should be shown for the key,
* false otherwise.
*/
function hintableKey(key) {
return (key === null || key === "." || maybeIdentifier(key));
function hintableKey(key, showOnDot) {
return (key === null || (showOnDot && key === ".") || maybeIdentifier(key));
}

/*
Expand Down
12 changes: 10 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ define(function (require, exports, module) {
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
noHintsOnDot = false, // preference setting to prevent hints on dot
ignoreChange; // can ignore next "change" event if true;


Expand All @@ -64,6 +65,9 @@ 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 prevent hints from being displayed when dot is typed
PreferencesManager.definePreference("jscodehints.noHintsOnDot", "boolean", false);

// This preference controls whether to create a session and process all JS files or not.
PreferencesManager.definePreference("codehint.JSHints", "boolean", true);

Expand All @@ -84,6 +88,10 @@ define(function (require, exports, module) {
jsHintsEnabled = _areHintsEnabled();
});

PreferencesManager.on("change", "jscodehints.noHintsOnDot", function () {
noHintsOnDot = !!PreferencesManager.get("jscodehints.noHintsOnDot");
});

/**
* Sets the configuration, generally for testing/debugging use.
* Configuration keys are merged into the current configuration.
Expand Down Expand Up @@ -426,7 +434,7 @@ define(function (require, exports, module) {
* @return {boolean} - can the provider provide hints for this session?
*/
JSHints.prototype.hasHints = function (editor, key) {
if (session && HintUtils.hintableKey(key)) {
if (session && HintUtils.hintableKey(key, !noHintsOnDot)) {

if (isHTMLFile(session.editor.document)) {
if (!isInlineScript(session.editor)) {
Expand Down Expand Up @@ -467,7 +475,7 @@ define(function (require, exports, module) {
var cursor = session.getCursor(),
token = session.getToken(cursor);

if (token && HintUtils.hintableKey(key) && HintUtils.hintable(token)) {
if (token && HintUtils.hintableKey(key, !noHintsOnDot) && HintUtils.hintable(token)) {
var type = session.getType(),
query = session.getQuery();

Expand Down

0 comments on commit e43a49f

Please sign in to comment.