Enabling JavaScript IntelliSense in External Libraries

To get JavaScript IntelliSense working in VS 2008 SP1, you need to tell IntelliSense the location of the libraries that you're using. You do that by adding a special comment at the top of the .js file. It's three slashes followed by the reference in an XML element syntax.

For example, my JScript.js file has a dependency on the jQuery library. So, here's what I add to the top of JScript.js:

/// <reference path="jquery-1.2.6.js" />

IntelliSense then parses the referenced file. Just start typing and you start seeing the jQuery members:

IntelliSense for JavaScript

I'm not sure whether it's required to put the reference pointer at the very top of the page but my IntelliSense failed to work when I included comments *before* the reference. The following didn't work:

/*-------------------------------------------------------------------- 
Don't do this!!!!!!!!!!!!
--------------------------------------------------------------------*/
/// <reference path="jquery-1.2.6.js" />

If the developer of a library wants to provide even more info, IntelliSense will pick that up too. Just use the three-slash comments with the following syntax:

trim: function(text)
{
    /// <summary>Removes whitespace from the beginning and end</summary>
    /// <param name="text">The string to be trimmed</param>
    /// <returns>string</returns>
    return (text || "").replace(/^\s+|\s+$/g, "");
},

Here's how the summary appears in the IDE for the trim() function above:

Including a Description

With IntelliSense, JavaScript debugging, and enhanced JavaScript formatting, I may start to hate JavaScript just a little less! <grin>

Ken

2 Comments

Comments have been disabled for this content.