Saturday, May 9, 2009

jQuery Intellisense in Visual Studio 2008 (VS 2008)

To enable intellisense completion for jQuery within VS you'll want to follow three steps:


Step 1: Install VS 2008 SP1

VS 2008 SP1 adds richer JavaScript intellisense support to Visual Studio, and adds code completion support for a broad range of JavaScript libraries.

You can download VS 2008 SP1 here.


Step 2: Install VS 2008 Patch KB958502 to Support "-vsdoc.js" Intellisense Files

Few weeks ago Microsoft shipped a patch that you can apply to VS 2008 SP1 that causes Visual Studio to check for the presence of an optional "-vsdoc.js" file when a JavaScript library is referenced, and if present to use this to drive the JavaScript intellisense engine.

These annotated "-vsdoc.js" files can include XML comments that provide help documentation for JavaScript methods, as well as additional code intellisense hints for dynamic JavaScript signatures that cannot automatically be inferred. You can download it here.


Step 3: Download the jQuery-vsdoc.js file

Microsoft worked with the jQuery team to put together a jQuery-vsdoc.js file that provides help comments and support for JavaScript intellisense on chained jQuery selector methods. You can download both jQuery and the jQuery-vsdoc file from the official download page on the jQuery.com site.

Save the jquery-vsdoc.js file next to your jquery.js file in your project (and make sure its naming prefix matches the jquery file name). For example, if the jQuery library file is jquery.1.2.6.js, the vsdoc file will be named jquery-.1.2.6-vsdoc.js


You can then reference the standard jquery file with an html <script/> element like so:

<script src="../Folder/jquery.1.2.6.js" type="text/javascript"></script>

When you do this VS will now look for a -vsdoc.js file in the same directory as the script file you are referencing, and if found will use it for help and intellisense.

No comments: