Philip Hendry's Blog

November 19, 2010

Javascript Intellisense in Visual studio 2008

Filed under: Tip, Visual Studio — philiphendry @ 12:14 pm

I don’t know about you but I’m a big fan of intellisense and for a while I’ve been using a simple hack to get javascript intellisense working. For example, I’ve just added the following lines to the master page :

<%-- A simple hack to fool Visual Studio into giving us intellisence for javascript --%>
<%if(false) {%><script type="text/javascript" language="javascript" src="ClientResources/Javascript/uitools.js"></script><%}%>
<%if(false) {%><script type="text/javascript" language="javascript" src="ClientResources/Javascript/jquery-1.3.2-vsdoc.js"></script><%}%>
<%if(false) {%><script type="text/javascript" language="javascript" src="/../lib/jqueryplugins/jquery.rms.ajaxprogress.js"></script><%}%>
<%if(false) {%><script type="text/javascript" language="javascript" src="/../lib/jqueryplugins/jquery.rms.ajaxhistory.js"></script><%}%>

There are a few things to note :

  • The if (false) is the neat little hack that means this will never get rendered but Visual Studio will still parse and provide intellisense for the references.
  • I’m including the jQuery using the vsdoc version which means the intellisense as slightly more information in it. For example :

    image
  • To extend our own javascript files with vsdoc info see Scott Guthries blog – it’s just a case of formatting the javascript comments.
  • You can also use parents paths out of the web site and into the lib folder!
  • This will also work with style sheets which means the underlining of styles telling you they don’t exist goes away! Admittedly you have to pick either a default one or a customer stylesheet but that’s better than nothing!
<%if(false){%><link href="../styles/Styles.css" rel="Stylesheet" type="text/css" /><%} /* Weird trick to resolve css references in the page without affecting compiled output */%>

About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: