Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add pref to prevent js code hints on dot #8476

Merged
merged 3 commits into from

3 participants

@redmunds
Collaborator

This is for #7706

Showing js code hints on dot messes up a coding style being used by some AngularJS users.

@JeffryBooher
Collaborator

Should probably have a unittest or two...

@redmunds
Collaborator

Added a unit test that tests when preference is both true and false. Ready fo ranother review.

@dangoor dangoor self-assigned this
@dangoor dangoor merged commit e17f084 into master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@dangoor

Looks good... and merged...

@dangoor dangoor deleted the randy/issue-7706 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 src/extensions/default/JavaScriptCodeHints/HintUtils.js
@@ -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));
}
/*
View
12 src/extensions/default/JavaScriptCodeHints/main.js
@@ -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;
@@ -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", 10000);
+ // 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);
@@ -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.
@@ -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)) {
@@ -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();
View
22 src/extensions/default/JavaScriptCodeHints/unittests.js
@@ -34,6 +34,7 @@ define(function (require, exports, module) {
EditorManager = brackets.getModule("editor/EditorManager"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
FileUtils = brackets.getModule("file/FileUtils"),
+ PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
UnitTestReporter = brackets.getModule("test/UnitTestReporter"),
JSCodeHints = require("main"),
@@ -1279,6 +1280,27 @@ define(function (require, exports, module) {
});
});
+ // Test `jscodehints.noHintsOnDot` preference
+ it("should consider dot a hintable key based on preference", function () {
+ var noHintsOnDot = PreferencesManager.get("jscodehints.noHintsOnDot");
+
+ testEditor.setCursorPos({ line: 44, ch: 10 });
+
+ // Default is falsey
+ expect(noHintsOnDot).toBeFalsy();
+
+ // Should get hints after dot
+ expectHints(JSCodeHints.jsHintProvider, ".");
+
+ // Set preference to true
+ PreferencesManager.set("jscodehints.noHintsOnDot", true);
+
+ // Should no longer get hints after dot
+ expectNoHints(JSCodeHints.jsHintProvider, ".");
+
+ // Set preference back to original value (converted to boolean)
+ PreferencesManager.set("jscodehints.noHintsOnDot", !!noHintsOnDot);
+ });
});
describe("JavaScript Code Hinting in a HTML file", function () {
Something went wrong with that request. Please try again.