Reputation:
I have functions1.js, functions2.js and functions3.js. Each has a function, funcA, funcB and funcC respectively. I created a file called "functions.intellisense.js" and added it to _reference.js. I then added a reference to _reference.js in my test.js file.
Why doesn't intellisense work?
functions.intellisense.js
intellisense.annotate(funcA, function () {
/// <signature>
/// <summary>Function A</summary>
/// </signature>
});
intellisense.annotate(funcC, function () {
/// <signature>
/// <summary>Function A</summary>
/// <param name="message">message</param>
/// </signature>
});
_reference.js
/// <reference path="functions.intellisense.js" />
functions1.js
function funcA() {
alert("this is function A");
}
functions3.js
function funcC(message) {
alert("this is function C " + mesage);
}
test.js
/// <reference path="Scripts/_reference.js" />
func //<--- expecting this to show intellisense
Is it even possible to do this? I'd like to do it for a couple reasons, first of all just combining documentation. Secondly, I'd like to be able to pre-document functions. Maybe prepend ideas with "TODO" so like if I haven't written the Test.Add() function, I could still put it in the intellisense file and it would popup with "TODO: Adds a test".
Upvotes: 0
Views: 538
Reputation: 1480
I commented already about how you have to setup your references - you have to declare functions before they're passed to intellisense.annotate if you want them to appear in IntelliSense. The function declaration drives the IntelliSense completion list, the annotate call updates the documentation for an already declared function.
I'd like to be able to pre-document functions. Maybe prepend ideas with "TODO" so like if I haven't written the Test.Add() function, I could still put it in the intellisense file and it would popup with "TODO: Adds a test".
You could do this by writing your own helper for IntelliSense, for example:
function stubFunction(functionName, annotation) {
if (!window[functionName]) {
window[functionName] = function () { };
}
intellisense.annotate(window[functionName], annotation);
}
Calling stubFunction
would create the stub function declaration and annotate it in one call:
stubFunction("funcA", function () {
/// <signature>
/// <summary>Function A does something important</summary>
/// </signature>
});
Now, if you type func
in the editor, you'll see funcA appear in the completion list with your documentation comments.
This stubFunction
utility could be placed in functions.intellisense.js and then used in that file to pre-document all your functions.
Upvotes: 1
Reputation:
If I modify functions.intellisense.js to include references to the script files containing the actual functions, it seems to work as expected.
/// <reference path="functions1.js" />
/// <reference path="functions3.js" />
intellisense.annotate(funcA, function () {
/// <signature>
/// <summary>Function A does something important</summary>
/// </signature>
});
intellisense.annotate(funcC, function () {
/// <signature>
/// <summary>Function C does something equally important</summary>
/// <param name="message">message</param>
/// </signature>
});
I was hoping to avoid this since as I said the functions may be stubs for functions that haven't even been written yet, but this still works. I'll wait to accept this answer to see if Jordan ha any more recommendations.
Upvotes: 0