mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
When typing, only automatically show hints for the "." character and JS identifier characters.
This commit is contained in:
1 parent
725a1e8553
commit
f6a073ca3d
4 files changed
+63
-51
No files matched your search
@@ -62,9 +62,7 @@ define(function (require, exports, module) {
|
||||
* @return {boolean} - could key be a valid identifier?
|
||||
*/
|
||||
function maybeIdentifier(key) {
|
||||
return (/[0-9a-z_.\$]/i).test(key) ||
|
||||
(key.indexOf(SINGLE_QUOTE) === 0) ||
|
||||
(key.indexOf(DOUBLE_QUOTE) === 0);
|
||||
return (/[0-9a-z_\$]/i).test(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +81,18 @@ define(function (require, exports, module) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if hints should be displayed for the given key.
|
||||
*
|
||||
* @param {string} key - key entered by the user
|
||||
* @return {boolean} true if the hints should be shown for the key,
|
||||
* false otherwise.
|
||||
*/
|
||||
function hintableKey(key) {
|
||||
return (key === null || key === "." || maybeIdentifier(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide a path into directory and filename parts
|
||||
*
|
||||
@@ -177,6 +186,7 @@ define(function (require, exports, module) {
|
||||
|
||||
exports.makeToken = makeToken;
|
||||
exports.hintable = hintable;
|
||||
exports.hintableKey = hintableKey;
|
||||
exports.maybeIdentifier = maybeIdentifier;
|
||||
exports.splitPath = splitPath;
|
||||
exports.eventName = eventName;
|
||||
|
||||
@@ -182,7 +182,9 @@ define(function (require, exports, module) {
|
||||
query = "";
|
||||
|
||||
if (token) {
|
||||
if (token.string !== "." && token.string !== "(" && token.string !== ',') {
|
||||
// If the token string is not an identifier, then the query string
|
||||
// is empty.
|
||||
if (HintUtils.maybeIdentifier(token.string)) {
|
||||
query = token.string.substring(0, token.string.length - (token.end - cursor.ch));
|
||||
query = query.trim();
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ define(function (require, exports, module) {
|
||||
* @return {boolean} - can the provider provide hints for this session?
|
||||
*/
|
||||
JSHints.prototype.hasHints = function (editor, key) {
|
||||
if (session && ((key === null) || HintUtils.maybeIdentifier(key))) {
|
||||
if (session && HintUtils.hintableKey(key)) {
|
||||
var cursor = session.getCursor(),
|
||||
token = session.getToken(cursor);
|
||||
|
||||
@@ -209,56 +209,54 @@ define(function (require, exports, module) {
|
||||
JSHints.prototype.getHints = function (key) {
|
||||
var cursor = session.getCursor(),
|
||||
token = session.getToken(cursor);
|
||||
if ((key === null) || HintUtils.hintable(token)) {
|
||||
if (token) {
|
||||
var type = session.getType(),
|
||||
query = session.getQuery();
|
||||
|
||||
// Compute fresh hints if none exist, or if the session
|
||||
// type has changed since the last hint computation
|
||||
if (!cachedHints ||
|
||||
type.property !== cachedType.property ||
|
||||
type.context !== cachedType.context ||
|
||||
type.showFunctionType !== cachedType.showFunctionType || query.length === 0) {
|
||||
var offset = session.getOffset(),
|
||||
scopeResponse = ScopeManager.requestHints(session, session.editor.document, offset),
|
||||
self = this;
|
||||
if (token && HintUtils.hintableKey(key) && HintUtils.hintable(token)) {
|
||||
var type = session.getType(),
|
||||
query = session.getQuery();
|
||||
|
||||
if (scopeResponse.hasOwnProperty("promise")) {
|
||||
var $deferredHints = $.Deferred();
|
||||
scopeResponse.promise.done(function () {
|
||||
cachedLine = cursor.line;
|
||||
cachedType = session.getType();
|
||||
matcher = new StringMatch.StringMatcher();
|
||||
cachedHints = session.getHints(query, matcher);
|
||||
// Compute fresh hints if none exist, or if the session
|
||||
// type has changed since the last hint computation
|
||||
if (!cachedHints ||
|
||||
type.property !== cachedType.property ||
|
||||
type.context !== cachedType.context ||
|
||||
type.showFunctionType !== cachedType.showFunctionType || query.length === 0) {
|
||||
var offset = session.getOffset(),
|
||||
scopeResponse = ScopeManager.requestHints(session, session.editor.document, offset),
|
||||
self = this;
|
||||
|
||||
$(self).triggerHandler("resolvedResponse", [cachedHints, cachedType]);
|
||||
|
||||
if ($deferredHints.state() === "pending") {
|
||||
query = session.getQuery();
|
||||
var hintResponse = getHintResponse(cachedHints, query, type);
|
||||
|
||||
$deferredHints.resolveWith(null, [hintResponse]);
|
||||
$(self).triggerHandler("hintResponse", [query]);
|
||||
}
|
||||
}).fail(function () {
|
||||
if ($deferredHints.state() === "pending") {
|
||||
$deferredHints.reject();
|
||||
}
|
||||
});
|
||||
|
||||
$(this).triggerHandler("deferredResponse");
|
||||
return $deferredHints;
|
||||
} else {
|
||||
if (scopeResponse.hasOwnProperty("promise")) {
|
||||
var $deferredHints = $.Deferred();
|
||||
scopeResponse.promise.done(function () {
|
||||
cachedLine = cursor.line;
|
||||
}
|
||||
}
|
||||
cachedType = session.getType();
|
||||
matcher = new StringMatch.StringMatcher();
|
||||
cachedHints = session.getHints(query, matcher);
|
||||
|
||||
if (cachedHints) {
|
||||
cachedHints = session.getHints(session.getQuery(), matcher);
|
||||
return getHintResponse(cachedHints, query, type);
|
||||
$(self).triggerHandler("resolvedResponse", [cachedHints, cachedType]);
|
||||
|
||||
if ($deferredHints.state() === "pending") {
|
||||
query = session.getQuery();
|
||||
var hintResponse = getHintResponse(cachedHints, query, type);
|
||||
|
||||
$deferredHints.resolveWith(null, [hintResponse]);
|
||||
$(self).triggerHandler("hintResponse", [query]);
|
||||
}
|
||||
}).fail(function () {
|
||||
if ($deferredHints.state() === "pending") {
|
||||
$deferredHints.reject();
|
||||
}
|
||||
});
|
||||
|
||||
$(this).triggerHandler("deferredResponse");
|
||||
return $deferredHints;
|
||||
} else {
|
||||
cachedLine = cursor.line;
|
||||
}
|
||||
}
|
||||
|
||||
if (cachedHints) {
|
||||
cachedHints = session.getHints(session.getQuery(), matcher);
|
||||
return getHintResponse(cachedHints, query, type);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -460,6 +460,8 @@ define(function (require, exports, module) {
|
||||
expectHints(JSCodeHints.jsHintProvider, ".");
|
||||
});
|
||||
|
||||
/* Single quote and double quote keys cause hasHints() to return false.
|
||||
It used to return true when string literals were supported.
|
||||
it("should list implicit hints when typing string literals (single quote)", function () {
|
||||
testEditor.setCursorPos({ line: 9, ch: 0 });
|
||||
expectHints(JSCodeHints.jsHintProvider, "'");
|
||||
@@ -469,7 +471,7 @@ define(function (require, exports, module) {
|
||||
testEditor.setCursorPos({ line: 9, ch: 0 });
|
||||
expectHints(JSCodeHints.jsHintProvider, "\"");
|
||||
});
|
||||
|
||||
*/
|
||||
it("should give priority to identifier names associated with the current context", function () {
|
||||
testEditor.setCursorPos({ line: 16, ch: 0 });
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
|
||||
Reference in new issue
Block a user