Skip to content

Commit

Permalink
fixes adobe-research#2 and adobe-research#4 - function type hinting
Browse files Browse the repository at this point in the history
Display the called properties name instead of "fn".
don't display "?" if the function type could not be determined.
  • Loading branch information
eztierney committed Apr 5, 2013
1 parent ecfb080 commit d545327
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ define(function (require, exports, module) {
}

} else if ( type.showFunctionType ) {
hints = this.fnType ? [{value:this.fnType, positions:[]}] : [];
hints = this.getFunctionTypeHint();
} else {
hints = ternHints || [];
hints.sort(compareIdentifiers());
Expand All @@ -539,6 +539,31 @@ define(function (require, exports, module) {
};
Session.prototype.setFnType = function (newFnType) {
this.fnType = newFnType;
};
};

/**
* Get the function type hint. This will format the hint so
* that it has the called variable name instead of just "fn()".
*/
Session.prototype.getFunctionTypeHint = function() {
var fnHint = this.fnType,
hints = [];

if (fnHint && (fnHint.substring(0,3) === "fn(")) {
var sessionType = this.getType(),
cursor = sessionType.functionCallPos,
token = cursor ? this.getToken(cursor) : undefined,
varName;
if (token) {
varName = token.string;
if (varName) {
fnHint = varName + fnHint.substr(2);
}
}
hints[0] = {value:fnHint, positions:[]};
}
return hints;
};

module.exports = Session;
});

0 comments on commit d545327

Please sign in to comment.