mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Merge pull request #8476 from adobe/randy/issue-7706
Add pref to prevent js code hints on dot
This commit is contained in:
commit
e17f08438a
3 files changed
+35
-4
No files matched your search
@@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in new issue
Block a user