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

Published Thursday, August 14, 2008 1:23 PM by Ken Cox [MVP]

Comments

# re: Enabling JavaScript IntelliSense in External Libraries

Wednesday, April 1, 2009 12:31 PM by Judy

I just installed VS 2008 sp1. My page works fine. It is just the intellisense for javascript does not work at all. Is there any property I need to change in order for intellisense to show up?

# re: Enabling JavaScript IntelliSense in External Libraries

Friday, January 14, 2011 5:10 AM by vikash

Please give me Code rush like tools for javascript in visual Studio

Leave a Comment

(required) 
(required) 
(optional)
(required)