I have a function $.publish
to publish a list of functions by binding the first argument to this
, and I'm intending to use it for writing X.prototype
, for example:
X.prototype = (function () {
function privateFunction(me) {
/// <summary>privateFunction</summary>
/// <param name="me" type="X"></param>
}
return $.publish({
publicFunction: function (me, a) {
/// <summary>publicFunction</summary>
/// <param name="me" type="X"></param>
/// <param name="a" type="Number"></param>
}
})
})();
So I can use X
like
var x = new X;
x.publicFunction(0);
The implementation of $.publish
in file lib.js
is
publish: function (fs) {
return $.map(fs, function () {
var f = this;
return function () {
f.apply(/* irrelevant */);
}
})
}
.
Problem
When I type x.publicFunction(
, the signature help only tell me that publicFunction()
, not knowing the param a
.
The MSDN doc - Adding IntelliSense Annotations says we can annotate a function like:
intellisense.annotate(someFunc, function (a) {
/// <signature>
/// <summary>Description of someFunc</summary>
/// <param name="a">Param a</param>
/// </signature>
});
So I wrote the following code in the lib.intellisense.js
:
$.publish = function (fs) {
/// <summary>Publish a list of functions</summary>
/// <param name="fs" type="Object">List of functions to publish</param>
return $.map(fs, function () {
var f = this;
var published = function () { };
//intellisense.redirectDefinition(published, f);
var funcSrc = f.toString();
var vsdocPattern = /^([ \t]+)(\/{3} .*)/mg;
var indent = -1;
var vsdoc = "";
for (var doc; (doc = vsdocPattern.exec(funcSrc)) != null;) {
if (indent < 0) {
indent = doc[1].length;
} else if (indent != doc[1].length) {
break;
}
if (doc[2].indexOf("<param name=\"me\"") > 0) {
continue;
}
vsdoc += doc[0] + "\n";
}
if (vsdoc != "") {
vsdocPattern.lastIndex = 0;
var funcHeader = funcSrc.substr(0, funcSrc.search(vsdocPattern));
funcHeader = funcHeader.replace(/(\(\s*)me(, )?/, "$1");
var annotation = "(" + funcHeader + vsdoc + "})";
//intellisense.annotate(published, eval(annotation));
return eval(annotation);
}
return published;
})
}
The result I get here is showing param a
when I type x.publicFunction(
, but the documents in the vsdoc are missing. I want the signature help to show the documents as well as the type info of the params, without repeating myself to copy and adjust the documents from x.js
to x.intellisense.js
, how?