This commit is contained in:
Kevin Dangoor committed 2013-04-22 10:16:23 -04:00
commit bb7b3c4ce4
42 files changed
+551 -284

No files matched your search

@@ -107,6 +107,10 @@ define(function (require, exports, module) {
if (token.keyword) {
$hintObj.addClass("keyword-hint");
}
if (token.literal) {
$hintObj.addClass("literal-hint");
}
// highlight the matched portion of each hint
if (token.stringRanges) {
@@ -160,6 +164,23 @@ define(function (require, exports, module) {
function JSHints() {
}
/**
* determine if the cached hint information should be invalidated and re-calculated
*
* @param {Session} session - the active hinting session
* @return {boolean} - true if the hints should be recalculated
*/
JSHints.prototype.needNewHints = function (session) {
var cursor = session.getCursor(),
type = session.getType();
return !cachedHints ||
cachedLine !== cursor.line ||
type.property !== cachedType.property ||
type.context !== cachedType.context ||
type.showFunctionType !== cachedType.showFunctionType;
};
/**
* Determine whether hints are available for a given editor context
*
@@ -178,15 +199,7 @@ define(function (require, exports, module) {
type = session.getType(),
query = session.getQuery();
// Invalidate cached information if: 1) no scope exists; 2) the
// cursor has moved a line; 3) the scope is dirty; or 4) if the
// cursor has moved into a different scope. Cached information
// is also reset on editor change.
if (!cachedHints ||
cachedLine !== cursor.line ||
type.property !== cachedType.property ||
type.context !== cachedType.context ||
type.showFunctionType !== cachedType.showFunctionType) {
if (this.needNewHints(session)) {
//console.log("clear hints");
cachedLine = null;
cachedHints = null;
@@ -215,10 +228,7 @@ define(function (require, exports, module) {
// 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) {
if (this.needNewHints(session)) {
var offset = session.getOffset(),
scopeResponse = ScopeManager.requestHints(session, session.editor.document, offset);
@@ -393,15 +403,11 @@ define(function (require, exports, module) {
if (resolvedPath) {
CommandManager.execute(Commands.FILE_OPEN, {fullPath: resolvedPath})
.done(function () {
session.editor.setCursorPos(jumpResp.start);
session.editor.setSelection(jumpResp.start, jumpResp.end);
session.editor.centerOnCursor();
session.editor.setSelection(jumpResp.start, jumpResp.end, true);
});
}
} else {
session.editor.setCursorPos(jumpResp.start);
session.editor.setSelection(jumpResp.start, jumpResp.end);
session.editor.centerOnCursor();
session.editor.setSelection(jumpResp.start, jumpResp.end, true);
}
}