Rich IntelliSense for jQuery

Rich IntelliSense for jQuery

  • Comments 73

Update: A new Hotfix is availble to complement this file.

A while back we updated VS2008 IntelliSense to not fail when referencing jQuery.  However, getting IntelliSense for chained calls and rich summary/parameter hints still required adding special comments to a few thousand lines of jQuery.  If you didn't have the time, you could download such a file from friendly members of the community such as James and Brennan.

As part of our new partnership with jQuery, yesterday we announced the availability of the official IntelliSense documentation file.  As you can see, our friends at jQuery have added a new download link for Visual Studio at http://docs.jquery.com/Downloading_jQuery#Download_jQuery.

image

You can also download the file directly from http://code.jquery.com/jquery-1.2.6-vsdoc.js.  As you might guess, this documentation file corresponds with the latest version of jQuery (which is currently 1.2.6).  While this file has a "js" extension, it's really just a documentation file.  You do not want to run this file in the browser.

How do I use this file (today)?

If you're inside an ASPX page, you will need to add the following lines of code into (normally) the head of your page:

image

Why do we have a server-side conditional statement?  IntelliSense disregards conditional statements of this type, and thus loads the "vsdoc" file (overriding the normal one).  At runtime the if (false) statement will ensure it this documentation file is not rendered (and executed) as script.  This trick allows the "switching" behavior you want.

If you're in a JavaScript file, use the normal file reference syntax to refer to the "vsdoc" file.

image

There's no need for tricks here since this comment is only meaningful to IntelliSense.

How do I use this file (in the near future)?

The ideal user experience should be one where you do not need special tricks as mentioned above.  Really, you shouldn't need to mention the "vsdoc" file name at all.  To that end, we plan on releasing a Hotfix that will enable this (stay tuned!).  Given normal references such as...

image image

...IntelliSense will opportunistically search for "jquery-1.2.6-vsdoc.js" and load that file instead.  Generally, given script name "x", IntelliSense will opportunistically search for "x-vsdoc.js".  If not found, it will then search for "x.debug.js".  You just need to make sure to place your "vsdoc" file next to the normal file.  Note, if you use jquery-1.2.6.min.js, you may need to rename the file to match the search pattern.

What are the advantages of this file?

One unique benefit of the file we have released is that it supports and understands jQuery plug-ins.  For example, given the plug-in below...

image

...you would see "myplugin" show up in IntelliSense.

image

We've noticed a few plug-ins do not work, and commonly this is because there is an IntelliSense incompatibility issue with the plug-in itself (as opposed to the jQuery documentation file).

Hope this helps!

Jeff King
Program Manager
Visual Studio Web Tools

  • Hello Jeff,

    I have downloaded the scripts and the documentation file as described above. Then I created test projects in VS 2005 and VS 2008. Here are my observations -

    1. In VS 2005, I am getting no intellisense. I tried everything.

    2. In VS 2008, I am getting intellisense. Also I have attached the jQuery files in my master page and that enabled the jQuery intellisense everywhere in my web site.

    Any idea what I need to do with VS 2005. We are still using VS 2005.

    Thanks,

    Shail

  • Hi Shail: I'm afraid VS2005 will not be able to support jQuery IntelliSense.  There were major changes made in VS2008 to enable the new functionality, and thus it's not something we can easily add to previous versions.

  • Hi Jeff,

    This sounds great, and I want to use it immediately...

    The thing that confuses me is do I need to remove the conditional statement before making a webpage live, or is it ok to have it run in a live environment?

    You say: 'You do not want to run this file in the browser.'

    I know this is temporary, but with how I have my sites setup I wouldn't want to add this line and then remove it before publishing all the time?!?

    Many thanks,

    Mark

  • What if I use MasterPage then in order to use intellisense in content page I have to put in content page or it can reference from master file also? (I have tons of content pages)

  • Hello Kumar,

    Yes, if you are using VS 2008. You can place script references as mentioned above, you will get intellisense in all your content page. You do not need to put any in content page. Placing reference in MasterPage is enough.

    Shail

  • Just one more thing,

    if you try to put that "<% if ( false ) %>" in header of your master page ( Because you want intellisense  in all your content pages ), you will get error  -

    "The Controls collection cannot be modified because the control contains code blocks <% ... %>..."

    Reason, your header is marked as runat="server". You can not remove that, themes won't work then

    You can fix that by moving that code block in the body of MasterPage, just after the form tag ( That is my case ). And now you will get intellisense in all your content pages.

    Shail

  • My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. The Web Developer Team announced that the official IntelliSence documentation file, which provides Rich IntelliSense for jQuery ,

  • How does it understand jQuery plug-ins? What makes a plug-in incompatible vs compatible for IntelliSense?

  • is there anyway to add this reference file to the web.config so it's global to Visual Studio?

  • The intellisense does not seem to work in a <script> element in a user control.  Is there a way to get this working?

  • Above, I meant to say, if you put the vsdoc reference in the master page, the intelliense does not work in a <script> element in a user control.  

  • Hi CurlyFro,

    I don't think so that currently there is any option to specify a script reference in web.config.

    Actually the Instellisense is something required at design time. There should be something like this - You can add a documentation file ( like one of jQuery ) to "Intellisense files" section of VS and that's all.

    May be we need to wait for next version of ASP.Net. May be the ASP.Net is working on this.

    Shail

  • Hello "Bob Reader",

    That is because a "Web User Control" can not use a MasterPage. MasterPage make sense with Pages. So the intellisense will not be available.

    I think, the best possible solution is to add the "<% if ( false ... %>"  code to your (I named it "jQueryIntellisense")in VS ToolBox ( Clip Board ??) and drag and drop to your UserControl when required. This will just save your time. I am using this manual hack for my UserControls

    Shail

  • You've been kicked (a good thing) - Trackback from DotNetKicks.com

  • Simple ASP.NET MVC Beta AJAX with jQuery!

Page 1 of 5 (73 items) 12345