Skip to content

Commit

Permalink
Merge pull request #9 from eztierney/iss-2-4
Browse files Browse the repository at this point in the history
fixes #2 and #4 - function type hinting
  • Loading branch information
dloverin committed Apr 5, 2013
2 parents ecfb080 + d545327 commit 7af5378
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 7af5378

Please sign in to comment.