views:

3658

answers:

9

I thought JQuery Intellisense was supposed to be improved with SP1. I even downloaded an annotated version of jquery 1.2.6, but intellisense will not work in a separate jscript file. I have the jquery library referenced first on my web page in the tag. Am I doing anything wrong?

+43  A: 

At the top of your external js file, add the following:

/// <reference path="jQuery.js"/>

Make sure the path is correct, relative to the file's position in the folder structure, etc.

Also, any references need to be at the top of the file, before any other text, including comments - literally, the very first thing in the file. Hopefully future version of VS will work regardless of where it is in the file, or maybe they will do something altogether different...

Once you have done that and saved the file, hit CTRL+SHIFT+J to force VS to update Intellisense.

Jason Bunting
That did it!! Thanks for the quick and correct answer!!
Mark Struzinski
No problem, glad I could help! Intellisense support for JavaScript has a long way to go yet, even with SP1 things are still a bit hackish, I think. Oh well, at least they are doing something to help! :)
Jason Bunting
FYI: I updated the title of this to reflect the fact that this is not specific just to jQuery, since it really isn't. Thanks for the question!
Jason Bunting
Also, to note, be sure that you use the PATH attribute rather than the NAME. I have seen many examples w/ :/// <reference name="jQuery.js"/> (INCORRECT)rather than/// <reference path="jQuery.js"/> (CORRECT)
Nathan
Yeah - uh, that's what my code indicates. Did I miss something?
Jason Bunting
Sweet. this has totally sorted me out. Thanks dude..
CraftyFella
You are welcome, glad I was able to help. :) And thanks to Stack Overflow too - this site makes getting and providing help so nice compared to any other medium...
Jason Bunting
shift-control-j will force intellisense to be recalculated.
Will
+9  A: 

You'll want to look at this link:

http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx

UPDATE: There is a new HotFix for Visual Studio 2008 and a new jQuery Intellisense Documentation file that brings full jQuery Intellisense to VS'08. Below are links to get these two:

http://blogs.msdn.com/webdevtools/archive/2008/11/07/hotfix-to-enable-vsdoc-js-intellisense-doc-files-is-now-available.aspx

http://blogs.msdn.com/webdevtools/archive/2008/10/28/rich-intellisense-for-jquery.aspx

Chris Pietschmann
If I could give you 10 votes I would. The programmatically generated intellisense-only file referenced here changes jQuery intellisense from near-useless to indispensable. Outstanding!
Herb Caudill
+13  A: 

There is an officially supported jQuery documentation javascript file for Visual Studio 2008. This file is only an interim fix until MS releases a hotfix that will more adequately address the issue.

Embedded in ASPX:

<% if (false) { %>
<script src="jquery-1.2.6-vsdoc.js" type="text/javascript"></script>
<% } %>

Embedded in JS:

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

Pick it up here: jquery-1.2.6-vsdoc.js

References:

JD Courtoy
+2  A: 

You shouldn't need to actually reference the "-vsdoc" version. If you put the jquery-1.2.6-vsdoc.js in the same directory as jquery-1.2.6.js then Visual Studio will know to covert a jquery-1.2.6.js reference to jquery-1.2.6-vsdoc.js.

I think that will actually work for any file.

Hmmm... that gives a good workaround for another question on this site...

Edit: This feature only works with VS2008 Service Pack 1.

Alan Oursland
It seems that I personally have to keep the "-vsdoc" in my reference to get it work... I am using VS2008 with SP 1. (And yes, these are in the same directory.) Maybe I need to look at those hotfixes suggested by Chris Pietschmann, above?
Funka
Chris is right. The 'vsdoc' functionality was added with the hotfix he references above.
Alan Oursland
+1  A: 

for inline javascript use:

/// <reference path="~\js\jquery-vsdoc.js"/>

note the BACKslashes.

this will not work:

/// <reference path="~/js/jquery-vsdoc.js"/>

A: 

make sure you're not using a minimized jQuery file

Ctrl+Shift+J to make it work after adding js files to the project

roman m
I have been struggling to get the intellisense working until I found this, because I was using the minified version and wondering why it wasn't working for me.
RKP
+2  A: 

If you are including the annotated jquery file in your source solely for intellisense, I recommend leveraging preprocessor directives to remove it from your view when you compile. Ala:

<% #if (false) %>
  <!-- This block is here for jquery intellisense only.  It will be removed by the compiler! -->
  <script type="text/javascript" src="Scripts/jquery-1.3.2-vsdoc.js"></script>
<% #endif %>

Then later in your code you can really reference jQuery. This is handy when using the Google AJAX Libraries API because you get all the benefits Google provides you, plus intellisense.

Here is a sample of using the Libraries API:

<script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
<script type="text/javascript">
   google.load("jquery", "1.3.2", { uncompressed: false });
</script>
nikmd23
A: 

If you want to pick up the Intellisense file from the Microsoft CDN you can use:

/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js" />
S. Miller