Hi,
I am trying to extend intellisense by adding a completionItem to a promise success-function variable (which happens to be a known loaded AMD module object - albeit its type is irrelevant to the problem at hand, it could be anything for which intellisense xml
comments have been setup).
At design time, the promise success-functions parameter is naturally unknown to intellisense but at runtime I would know all about the parameter type and contents of course. Therefore I want to add one or more completionItems to it at design time through my
own custom intellisense extension.
Example client-code script:
/// <reference path="/Scripts/SomeObject.intellisense.js" />
SomeObject. // Intellisense works here.
SomeActionThatReturnsAPromise().then(
function success(SomeObject) {
SomeObject. // Intellisense wanted here too.
},
function failure(errorMessage) {
alert(errorMessage);
}
);
Example intellisense file referenced above in client-code script:
intellisense.logMessage("SomeObject Intellisense has been activated.");
// SomeObject description enriched with intellisense for Visual Studio.
var SomeObject = {
SomeMethod: function (a) {
/// <summary>SomeObject.SomeMethod function description</summary>
/// <param name="a" type="String">A string parameter value</param>
/// <returns type="String" />
}
};
intellisense.addEventListener('statementcompletion', function (event) {
intellisense.logMessage("Target object: " + JSON.stringify(event.target));
intellisense.logMessage("Target name: " + event.targetName);
intellisense.logMessage("Num completion items: " + event.items.length);
// Regardless of what intellisense picks up, try to add the function to the completionItems array. This works like a charm!
event.items.push(
{
name: 'SomeMethod',
kind: 'method',
parentObject: SomeObject,
value: SomeObject.SomeMethod,
comments: intellisense.getFunctionComments(SomeObject.SomeMethod),
glyph: 'vs:GlyphGroupInterface' // Just to see if I can change the glyph.
}
);
if (event.targetName === "SomeObject" && event.target === undefined) {
// This is where I would like to add the completionItem
// but intellisense does nothing when the items.push code
// is placed here. I speculate that the event.target === undefined
// is the reason for the failure to add completionItems /
// affect the items array.
//
// Intellisense reports the following for the "SomeObject." inside the success-function:
// "intellisense was unable to determine an accurate completion list".
}
});
I have tried to add a completionItem to the SomeObject function parameter by calling:
intellisense.addEventListener('statementcompletion', function (event) {
if (event.targetName === "SomeObject" && event.target === undefined) {
event.items.push(
{
name: 'SomeMethod',
kind: 'method',
parentObject: SomeObject,
value: SomeObject.SomeMethod,
comments: intellisense.getFunctionComments(SomeObject.SomeMethod),
glyph: 'vs:GlyphGroupInterface' // Just to see if I can change the glyph.
}
);
// Nothins happens?
}
});
As can be reproduced by the above scripts in VS2012, the target comes out as undefined. I presume this is the reason for failing to add the completionItem to events.items?
Please advice on how to achieve this - thanks!
Best regards,
Michael S. Fosgerau
Denmark