2
/// <reference path="jquery-1.5.vsdoc.js" />
// IntelliSense works here.

function ($, window, document, undefined) { /// <param name="$" type="jQuery" />
    // IntelliSense  does not work here.

}(jQuery, this, document);

Is there a workaround for Visual Studio 2008? The SP1 hotfix has been applied and is the reason the IntelliSense works outside of the no-conflict wrapper but, inside, no bueno. Some have said to add the param annotation but, alas, that doesn't work either for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Code Maverick
  • 20,171
  • 12
  • 62
  • 114
  • The question title is not for tags, you should write a title that describes your actual problem. – Brandon Mar 29 '11 at 16:44
  • @Scott, it wasn't meant to troll you, just a helpful suggestion. Descriptive titles can help your question get more attention while non-descriptive titles may get your question ignored. If you disagree, you can always revert it back. – Brandon Mar 29 '11 at 17:12
  • possible duplicate of [Intellisense for special javascript function](http://stackoverflow.com/questions/5459111/intellisense-for-special-javascript-function) – Daniel A. White Mar 29 '11 at 17:28
  • Yes and no. You have the same issue but in a different IDE, Visual Studio 2010. I'm in Visual Studio 2008 SP1 with the vsdoc intellisense hotfix patch applied. I did read yours before posting mine. They might have the same answer though. – Code Maverick Mar 29 '11 at 17:35

2 Answers2

3

It's because the definition of the function doesn't know that jQuery means dollar inside of it. Take this for example:

var wrapper = function($, window, document, undefined) {
    // this function doesn't know what dollar is
};

// it could be called like this:
wrapper(jQuery, window, document, undefined);

// or like this:
wrapper(1, 2, 3, 4);

Your function cannot know the definition of what you are passing in. It is up to your function to figure that out and make sure your arguments are valid.

The definition of the function and the execution of the function are two separate things. You will not get intellisense for function arguments inside of the function definition.

Eli
  • 17,397
  • 4
  • 36
  • 49
  • I mean, I get that the function doesn't know what's being passed in, but that's what the param annotation is supposed to be doing. It's explicitly giving the the $ parameter a typeof jQuery. – Code Maverick Mar 29 '11 at 17:40
  • 1
    Something else that is bugging me is your example. What I have in my post is a self-executing function. It calls itself via the (jQuery, this, document). Even though you didn't use a self-executing function in your example, I suppose what you are saying in your answer would still hold true with self-executing functions? And if that's the case, I would still question why explicit param/type definition of /// doesn't work. – Code Maverick Mar 29 '11 at 17:56
  • 1
    Remember that your param is trying to determine the type of the parameter, which is OF TYPE jQuery, not jQuery itself. This is also a known limitation of JavaScript intelliense of not having param definition inside of execution context. – Eli Mar 29 '11 at 18:06
  • So what you are saying is that the /// will never work? – Code Maverick Mar 29 '11 at 18:44
  • 1
    Correct. Maybe someday it will be able to determine that you are passing in a jQuery instance (`$('.someclass')`), but not jQuery itself, and not at this time. – Eli Mar 30 '11 at 15:31
1

This works for me in Visual Studio 2010 with the jQuery IntelliSense documentation included from the NuGet package (currently 1.6.1). There is one hack, but this is an example jQuery plugin with full IntelliSense of the jQuery instance.

/// <reference path="/Scripts/jquery-1.6.1.js" />
(function ($) {
    /// <param name="$" type="jQuery">
    ///     Pass me jQuery
    /// </param>

    // IntelliSense works here.
    $(".intellisense_work_here").add(".test", "<strong>it works<strong>");

    // Setting this locally enables IntelliSense  to work in the .each below.
    var $ = $;

    $.fn.makeThingsAwesomePlugin = function (options) {

        var defaults = {
            awesomeness: "really_awesome"
        };
        var options = $.extend(defaults, options);

        return this.each(function () {

            // intellisense work here    
            $(".someting_lame").addClass(options.awesomeness);
        });
    };
})(jQuery);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jon Kragh
  • 4,529
  • 5
  • 26
  • 26
  • First, what is nuGet? Second, we are still using VS2008 and haven't fully upgraded to VS2010 yet. – Code Maverick May 20 '11 at 17:23
  • This is nuGet: http://www.nuget.org/ Supposedly it has updated jQuery docs, but I'm not sure if it has any affect on this issue. I don't have vs2008 anymore, but maybe you can try the above and see if it works? It might possibly work in VS2008 as well. – Jon Kragh May 20 '11 at 17:31
  • I just re-looked at your example and I guess you tried something very similar already. All that I can say is that my combo of code above works but I'm not sure of the most important factor of it: vs2010, updated jquery docs, etc. – Jon Kragh May 20 '11 at 17:41
  • Yea I think it's more likely that its a 2008 vs 2010 thing. 1.6.1-vsdoc doesn't even compile the IntelliSense for me in VS2008. Always has errors, even with the hotfix installed. – Code Maverick May 20 '11 at 17:52