Friday Tip 06, We love Visual Studio Intellisense, Lets love it more

We, Developers, love nothing in Visual Studio more than its intellisense, Right ?? Yes off course, I guess that’s my readers answer if they have been using visual studio for sometime.

why not, since it’s getting smarter, no lets say more intelligent with every release of Microsoft Visual Studio.

Today I’ll be discussing special area of VS intellisense that VS 2008 brought to further make developers happier. That would be JavaScript intellisense along with the latest additions to the intellisense package which is Jquery Intellisense.
There is more,

First: Javascrip Intellisense

Scripting javascript before VS 2008 and after in VS is totally different. You simpley get the power of scripting with the joy of intellisense rather than trying to remember what a particular method name is or even having your favorite search engine warmed up with javascript names searches.

Either you script within your page or in a separate file you will get the intellisense like below

What about your own javascript ?? For sure you need intellisense for javascript you wrote in separate javascript files to be seen from pages or even other javascript files. You got that too. In below screens I have a javascript file “main.js” that has function called ShowLove(). You can see in the second screen that I can see it from my aspx page and all I needed is to add a refernce to the js file like we all used to.:

I know You are smart enough and had noticed the help tip “Show love alert”. if you went back to the method declartion you will notice the documentation line in the begining of the method body. Remember you of something ?? Didn’t I tell you that you are smart, that’s right the XML documentation in our .net code and off course it has the same functionality of providing help to whom consuming your methods. But remember in .net we write our XML comments before method or class declaration where in Javascript we write them at the begining of methods. In the refernces at the end of the article you will find a great article about javascript intellisense comments to get more about them.

Now, what about calling javascript written in javascript file from another javascript file? To do this you will need to refernce your source javascript file at the begining of your destination file “where you want to call that javascript” and the syntax is simple as below:

If you are not installing VS 2008 SP1 the above example won’t work for you until installing this HotFix. I will recommend you to install the SP1 which we will need for the other part of this article Jquery Intellisense.

The fun doesn’t stop here, Actually the fun will just start with the second part of this article “just below” so lets have fun …

Second: Jquery Intellisense

If you have been a web developer for a while, for sure you have come acrross Jquery and moreover you may have become a fan like most of us. Since I assume you already know what Jquery is lets not talk about it and get to our point. Afterall we all know how light, delight, effictive, easy, powerfull and time saving javascript utility is Jquery. Microsoft knew it as well and that’s why they decided to add Jquery Intellisense for Visual Studion with collaboration of Jquery team.

To use this great addition to Intellisense, you will need the following :

1- Download and install VS 2008 SP1

2- Downloa and install this patch to support vsdococ.js files.

3- Download Jquery and Jquery-vsdoc.js files

After you finished add Jquery file along with the vsdoc file in the same directory

Make a reference to your jquery in your page or javascript file and have fun getting Jquery intellisense in your visual studio

Some Tips

While enjoing javascript and jquery intellisense in Visual Studio I came through few tips that I’ll share with you. They can simply save you sometime in one busy day  when tiny little things become invisible.

1- when using Master Page that is not in the same directory as its content page and you want to write javascript inside that page, you will need to change your javascript/jaquery refernce to represent how master page see your javascript/jquery at develpment time which is opposed to run time. consider the below file structure

To be able to use intellisense from that master page your javascript refernce will be like below

However for your javascript to run in the browser you will need to update your javascript refernce since master pages are not actually pages and rendered as part of their content pages.

2- Make sure that the vsdoc file has exactly the same name as the jquery file plus -vsdoc.js. I say that because the latest version of jsdoc to download from jquery site ends with vsdoc2.js which you need to convert to jsdoc.js to work. Moreover to use the minified version of jquery you will need to remove min part from the name.

3- Sometimes The intellisense doesn’t work immediatly so you may need to give a cariage return to start writing on a new line so that visual studio can bring you intellisense. so when ever you get this situation, you may close and reopen your page or js file and start writing on a new line. I don’t have a logical explanation for this situation but I have come through it several times and that’s how it worked out with me.

Below are some reference articles that you will find great and provide more explantions :

http://weblogs.asp.net/scottgu/archive/2007/06/21/vs-2008-javascript-intellisense.aspx

http://weblogs.asp.net/bleroy/archive/2007/04/23/the-format-for-javascript-doc-comments.aspx

http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx

This Post is on

Bookmark and Share

This entry was posted on Friday, May 15th, 2009 at 5:14 pm and is filed under Friday Tip. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply