Welcome to MSDN Blogs Sign in | Join | Help

Visual Web Developer Team Blog

Your official information source from the Visual Web Developer team.

News

  • These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified Terms of Use
JScript IntelliSense FAQ

I've been reading through the 70 or so comments on our last 2 jQuery posts.  There have been a lot of great questions.  Apologies for not being able to answer them sooner (I was busy preparing for Dev Connections).  Instead of answering them inline with the comments, I'll try to paraphrase the popular issues here and answer them centrally.

1. I have a ton of Content Pages, do I need to put script references for IntelliSense in each one?

No, you do not need to repeat the script references on each content page.  Visual Studio 2008 will auto-detect the presence of a master page and scan for references in that file.  Thus, placing references in the master page is all you need to do.

2. I put a vsdoc reference in the Master Page, why is IntelliSense not working in a User Control?

User Controls do not specify a master page.  Thus, there is no way for Visual Studio to guess which master page the user control will end up on.  Generally, we simply can't predict which file a user control will end up on.  Thus, we are unable to provide IntelliSense.

"Shail" provided the best suggestion, which is just to include a list of script references you want on your user control, then wrap those controls with a "<% if (false) ... %>" to make sure you don't redundantly include scripts at runtime.

I can see a centralized list of references helping this scenario, which leads into the next question...

3. Is there a way to specify a centralized list of references for IntelliSense?

Unfortunately, not right now.  Short of writing your own ScriptManager or similar code, there's no "built-in" way to specify a centralized list of references for IntelliSense (or for the runtime).  There's no web.config location for this (as "CurlyFro" asked) nor is there a Tools Options list you can set.

However, there is a fairly useful trick that is worth mentioning.  You can create a JS file with no code (let's call it "list.js") that contains solely a list of commonly used references (the XML comment type) at the top.  Instead of putting a list of individual references on top of each JS file, you can simply include just a reference to "list.js".  The meta-point here is that references originating from a script (not HTML/ASPX) file are transitive.  If A references B, and B references C and D... A effectively references B,C, and D.  Having the centralized file saves you from updating 100's of files when you add one more script to your project.  As mentioned above, Master Pages serve as a unified place to put scripts for HTML/ASPX pages.

"Peter" suggested there was a similar issue with CSS files.  Given the feedback, this is something we can definitely take into consideration.  I'm curious: how many files you are typically including into your pages?  Will the workarounds provided suffice?

4. Which URL-path types does IntelliSense recognize?

I saw a lot of questions/feedback/comments regarding paths and URLs.  I'd like to clarify what is supported and not supported by Visual Studio JScript IntelliSense then ask for feedback:

  • File-Relative Paths - These are paths of the form "../../folder/file", and is calculated from the current file(http://site/application/folder/file).  Visual Studio, ASP.NET Web Forms, and ASP.NET MVC all support this type of path and resolve these correctly.  The challenge, however, is with master pages.  This type of path is not re-based when a master page is merged with a content page. Thus if you content pages are at varying folder depths, your paths will be broken.  Incidentally, ASP.NET MVC folder paths tend to be exactly two levels deep because of the conventional MVC dictated folder structure of "Views/ControllerName".  Because of this, I would recommend this type of path for MVC, but not for Web Forms.
  • App-Relative Paths - These are paths of the form "~/folder/file", and is calculated from the base of your application (http://site/application/folder/file).  Visual Studio and ASP.NET Web Forms both support this type of path provided you specify it inside a Script Manager (and a few other runat=server controls).  Since ASP.NET MVC is not normally used with Script Manager controls, app-relative paths will not work with MVC.  By the way, this type of syntax is not supported inside plain <script> tags regardless of technology.  App-relative paths are re-based when a master page is merged with a content page.  Thus it is not broken by content pages at varying folder depths.  Thus I would recommend this approach for Web Forms.  The Script Manager normally injects MS AJAX into your rendered page.  What if you are not using MS AJAX?  The Script Manager can be modified to not to inject MS AJAX.
  • Site-Relative Paths - These are paths of the form "/folder/file", and is calculated from the base of your site (http://site/application/folder/file).  This approach is supported by ASP.NET Web Forms and ASP.NET MVC.  However, it is not supported by Visual Studio.  The reason is because Visual Studio does not always know the final deployed location of your site and thus the path resolution cannot be guaranteed.  Given that quite we've seen few folks are using site-relative paths, we could consider making an assumption just resolving this type of path to the root of the project.  Given the risk that you may think your site is working when it's really not, I wanted to see how many people were supportive of this.
  • Absolute Paths - Obviously, by absolute, I mean paths of the form "http://site/etc".  Note, as of Service Pack 1, we will now resolve this type of path... fetching the file over the network if necessary.

In a nutshell, I'm recommending ../../folder/file for MVC and ~/folder/file for Web Forms.  Also, we can resolve site-relative paths to the project root for if there's enough demand.

5. How do I get IntelliSense to understand "google.load()"?

The google API has a dynamic way of including script files via the "load" function.  Unfortunately, IntelliSense will not be able to understand that this function brings in new scripts.  My recommendation here would be to include your file statically via a <script> tag.  You can wrap it a "<% if (false) ... %>" if you won't want to double-include the script at runtime.

6. I'm getting a "childNodes is null" error, what is it and what do I do?

If you're using jQuery, the "childNodes" error is indicative of IntelliSense not happy with a particular plug-in.  Note, the error will misleadingly point to the jquery-1.2.6-vsdoc.js file.  The cascading set of errors lands in the core jQuery code, however it originates from the plug-in.  For example, the jQuery UI DatePicker is one of the plug-ins that will show this error.

Generally for any JavaScript library, a "childNodes" error is caused by libraries that try to create DOM elements on parse rather than slightly later on load.  DOM element creation is not supported at design-time (IntelliSense-time as I call it) and thus you get a null reference exception when you try to call "childNodes" on the element.  Note, this is a perfectly acceptable pattern... it's our fault that it causes an error.  In fact, we've made some major architectural changes to accommodate this in Visual Studio 2010 but I'll save that for another post.

We will try to work with library owners to product VSDOC files for their libraries in the future.  For now, the best option is to hide the file from IntelliSense...  see question #8.

7. What makes a jQuery plug-in incompatible or compatible for IntelliSense?

There's no hard and fast rule for compatibility with IntelliSense.  However, from my experience, if a plug-in is going be incompatible, it's going to be because it tries to create and modify a DOM element before the document is ready.  Please see the previous question for more details.  If you frequently see another type of issue, please let us know (via a comment on this post or you can email me... address at the bottom) and we'll be sure to investigate to provide an explanation.

8. How do I hide a file from IntelliSense?

"Igor" came up with a clever solution outside the box of what the "vsdoc" feature was originally intended for. =)  However, I think it's great and worth repeating.  You simply create a empty -vsdoc.js file for the offending library... effectively making Visual Studio skip the problematic ones.  Of course this means you get less IntelliSense, but it's better than none.

9. Can you add support to recognize more file extensions?

I saw a request from "Jerry" to recognize the "dash debug" convention.  I also saw some folks mistakenly use a "dot vsdoc" naming scheme.  Note vsdoc is supposed to be a "dash vsdoc" rather than "dot".  Of course there's also the "dot min" extension for compressed files.  We can definitely add support for more file extensions in a future release.  Feedback for which ones are the most important would be helpful in making sure we support the right set.

10. In Visual Studio 2005 I am getting no IntelliSense, what do I need to do?

You'll need to upgrade to Visual Studio 2008.  I hate to pull the "buy a new version" card, but JScript IntelliSense was a fairly involved code change and it would be non-trivial to back-port it to Visual Studio 2005.

11. Is there a way to get around closing and reopening an file to get Visual Studio to update IntelliSense?

Yes.  Please use Ctrl + Shift + J to manually force JScript IntelliSense to update.  For menu-lovers, this command can be found under Edit, IntelliSense, Update JScript IntelliSense.

Summary

I hope this FAQ clears up the common points of confusion.  I saw a few comments akin to "because of ____, this feature is useless to me."  As harsh as they sound, those comments are the most useful to us.  If there's something in your way, feel free to email me at jking at microsoft dot com.  I'd like to see if there's something we can figure out for you.  Thanks for reading!

Jeff King
Program Manager
Visual Studio Web Tools

Comments

Joel Varty said:

One of the biggest pain points that I find with Visual Studio 2008 is its inconsistency with IntelliSense

# November 19, 2008 9:20 AM

ormico said:

Thanks for the [CTRL]+[SHIFT]+J

VS has a bunch of keyboard shortcuts mostof which I don't know or can't memorize. Is there a master list somewhere? I always have a similiar complaint about commands in the Immediate and Command windows. I miss the printed manual.:)

# November 19, 2008 10:27 AM

DotNetKicks.com said:

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

# November 19, 2008 11:16 AM

SharpGIS said:

"because of _my_scripts_are_being_included_by_custom controls_ and_intellisense_doesn't_work_on_those_scripts, this feature is useless to me." :-)

The ScriptManager is the only control that does support this, but I suspect that is because Microsoft "cheated" in their implementation of intellisense.

# November 19, 2008 2:39 PM

WebDevTools said:

@SharpGIS

That's fair enough, I've definitely heard that feedback.  And yes, the ScriptManager does get a bit of special treatment in that regard.  Just to for me to get more context, how many custom controls are you using per project?  how many scripts on average does each control include?  are any of the scripts dynamically included based special logic or is it always the same set?

# November 19, 2008 4:50 PM

CurlyFro said:

it’s encouraging to know that Microsoft is listening and adding jQuery support is a start. but Microsoft has an opportunity to fully build out it’s  IDE for javascript  - better intellisense and a ‘Go To Definition’ and ‘Find All References’ would be a great addition.

developers still need to depend on Firebug or the like.  Microsoft has cool server-side debugging but those same debugging techniques needs to come into the client-side as well + Firebug like integration.

# November 20, 2008 10:27 AM

WebDevTools said:

@CurlyFro: Have you tried the updated IE8 Dev Toolbar?

# November 20, 2008 9:42 PM

ScottGu's Blog said:

Last month I blogged about how Microsoft is extending support for jQuery .&#160; Over the last few weeks

# November 21, 2008 5:07 AM

BusinessRx Reading List said:

Last month I blogged about how Microsoft is extending support for jQuery .&#160; Over the last few weeks

# November 21, 2008 5:41 AM

Stephen said:

Regarding #6  (childnodes error), is there any way (log file or something) to see what Studio is looking for?

I've just done the "fake" -vsdoc.js for all my jQuery plugins and i am *still* getting the error

# November 21, 2008 9:12 AM

WebDevTools said:

@Stephen: What scripts do you have remaining?  Also what do you see in your error list?  Really do feel free to email me at jking at microsoft dot com and we can diagnose the issue faster.  Thanks!

# November 21, 2008 12:09 PM

Kai.Ma said:

【原文地址】jQueryIntellisenseinVS2008【原文发表日期】Friday,November21,20082:07AM

上个月,我在博客里宣布了微软...

# November 23, 2008 3:12 AM

Rick Strahl said:

A lot of these issues could be addressed if there was a way to make a <script> tag that works server side (ie. runat="server" type behavior). This obviously wouldn't work since that connotates different meaning, but maybe you could have an asp:script tag that has basically the same syntax as stock script but allows for things like relative paths and setting visibility (which would hide the script at runtime).

Similar thing for <asp:link> in headers.

I've often wished for this behavior. I've actually tried to create something custom for this but the problem is that as soon as you namespace those tags Intellisense no longer recognizes them and so this would have to be fixed in VS...

# November 23, 2008 4:09 PM

Sia said:

In the case of an ASP.NET MVC, the: recommended “../../folder/file” for MVC forms works fine to get intellisense in visual studio. However the browser can’t find the JS file when you are viewing a page that is using the default (index) controller action or one without an ID. For example the following URL works:

http://localhost/MyApp/Home/Contact/1">http://localhost/MyApp/Home/Contact/1

The script tag is as follows <script src="../../Scripts/JQuery.js" type="text/javascript"></script>. And this is within my site.master file.

However if the URL is like the one below (i.e. I don’t need an ID as part of the URL)

http://localhost/MyApp/Home/Contact

doesn’t work. If I have the script tag as “../Scripts/JQuery.js” then the browser finds the JS correctly.

Any suggestions?

# November 23, 2008 8:02 PM

Martillo said:

Thank you for the excellent post.

I just wanted to cast a vote for Site Relative Paths.

I'd also like to second Rick Strahl's motion for asp:script tags.

# November 24, 2008 12:07 AM

binglingshui said:

[转自MSDN]

在VS2008中启用jQueryIntellisense的步骤

要在VS中启用jQuery的intellisense完成,你要遵循三个步骤:

第一步:安装VS2008...

# November 24, 2008 3:29 AM

orip said:

The '.min.js' and '.pack.js' conventions are pretty popular, and also used by jQuery itself.

# November 24, 2008 9:04 AM

courage_dog said:

I hope you just got some inspirations for VS2010, Extensibility Framework and the Intellisense ;-)

Thanks for nice post!!

# November 24, 2008 3:35 PM

WebDevTools said:

@Rick Strahl: Link tags under head (runat server) will currently rebase properly. I think it might be worthwhile to ask ASP.NET (Bertrand) to do the same for the script tag.  There have also been many requests for a ScriptManager that is not tied to ASPNET AJAX.  Either approach should solve the issue.

# November 24, 2008 5:30 PM

WebDevTools said:

@Sia: Yes, the absolute paths definitely don't work for all cases.  A dirty approach would be to include the same scripts a few times at varying path depths. =)  It's ugly, but it's a workaround... and you won't re-include scripts since only one will resolve properly.  We'll be looking for a more robust way moving foward.  Thanks for your feedback!

# November 24, 2008 5:33 PM

WebDevTools said:

@orip: Thanks!  .min.js and .pack.js have been noted.  I'd love to hear any other requets... it's been quiet so far. =)

# November 24, 2008 5:34 PM

Sia said:

Thanks Jeff for your response. Actually for anyone else interested. The way I currently do it, which I prefer over the multiple same scripts at varying depths, is to do (in the master page) one only: <script src="<%=ResolveClientUrl("~/Scripts/JQuery.js")%>" type="text/javascript"></script>. And for intellisense to work I do <%if(false){%> <script src="../../Scripts/JQuery.js" type="text/javascript"></script><%}%> in the same master page. And that works for all controller action cases and at any level.

# November 24, 2008 6:58 PM

gOODiDEA.NET said:

.NET Redirecting without the exceptions So, what&#8217;s new in the CLR 4.0 GC? Source Control for Visual

# November 24, 2008 8:18 PM

小角色 said:

【原文地址】jQuery Intellisense in VS 2008 【原文发表日期】 Friday, November 21, 2008 2:07 AM 上个月,我在博客里宣布了微软将对jQuery提供支持。在过去的几个星期里,我们与jQuery开发团队合作,在Studio 2008 和 Visual Web Developer 2008 Express版本(免费的)中增加了很好的jQuery intellisense支持。现在这个支持可以下载使用了。 在VS 2008中启用jQuery Intellisense的步骤

# November 24, 2008 9:12 PM

Web Development Community said:

You are voted (great) - Trackback from Web Development Community

# November 25, 2008 11:03 AM

netCoder said:

"The way I currently do it, which I prefer over the multiple same scripts at varying depths, is to do (in the master page) one only: <script src="<%=ResolveClientUrl("~/Scripts/JQuery.js")%>" type="text/javascript"></script>. And for intellisense to work I do <%if(false){%> <script src="../../Scripts/JQuery.js" type="text/javascript"></script><%}%> in the same master page. And that works for all controller action cases and at any level."

Sia I was able to get the same approach to work at any level with ASP.NET forms with one minor change. Use <%if(false){%> <script src="~/Scripts/JQuery.js" type="text/javascript"></script><%}%>

I included this right under my form tag in the master page.

One thing I am want to figure out and dont know if it's even possible at this point is to use intellisense with noConflict. Currently two of my entire sites are using var $j = jQuery.noConflict();

Anyone have a solution for this?

Vin

# November 25, 2008 11:05 AM

Felix Wang | Evangelizing the Next Web said:

【原文地址】 jQuery Intellisense in VS 2008 | VS 2008中的jQuery Intellisense 【原文发表日期】 Friday, November 21, 2008

# November 27, 2008 12:33 AM

ScottGu's Blog em Português said:

Mês passado eu postei sobre como a Microsoft está estendendo o suporte à jQuery . Nas últimas semanas

# December 3, 2008 10:12 PM

. said:

Another vote for Site-Relative Paths. I don't use File-Relative in case the structure changes.

# December 9, 2008 1:06 PM

Jon Sagara said:

Not sure if it's too late, but I, too, would like VS to support Site-Relative Paths.

# December 14, 2008 8:30 PM

不懂.NET said:

jQuery Intellisense in VS 2008 转自:http://weblogs.asp.net/scottgu/ Last month I blogged about how Microsoft is extending support for jQuery. Over the last few weeks we've been working with the jQuery team to add great jQuery intellisense support within

# December 15, 2008 12:08 AM

Website Design said:

I agree with you. I think it is a good tool to use.

# December 16, 2008 11:30 PM

John said:

Hi Jeff, I'm currently using VS 2008 TS to write some JavaScript code. The best part IMHO is the absolutely fantastic integrated debugger, but what annoys me is the lack of bracket highlighting. If i write function(key) and put the cursor after ), the ( symbol doesn't change it's color, like it does in C#. Is this a limitation of the IDE or just a problem with my config? TIA

# January 14, 2009 3:54 AM

James.ToString() said:

JQuery 1.3 and Visual Studio 2008 IntelliSense

# January 14, 2009 12:31 PM

Luke said:

Keep getting this error every time I try to update intellisense....

Warning 130 Error updating JScript IntelliSense: C:\Users\lukas\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\V1QNKBDO\wt-fds90[1]..js: Object doesn't support this property or method @ 540:2

# January 29, 2009 4:55 PM

WebDevTools said:

@Luke: Any particular reason you're referencing a temp internet file which I assume to be outside of your project?  Most likely a getElementById call or createElement call has returned null and on line 540 the invocation of a method off that object fails.  If possible, I would try to comment out that invocation.

# January 29, 2009 6:02 PM

Luke said:

It's actually the webtrends (wt.js) file that is causing issues for some reason. I have not been able to figure out exactly why yet. I have not been able to find anything online about it.

Here is the file.

http://js.microsoft.com/library/mnp/2/wt/js/wt.js

Ping me if you want (lukas).

# January 29, 2009 6:48 PM

Tim Gaunt said:

We use absolute (or as you refer to them -Site-Relative Paths) URLs to work around URL rewriting as a site might be many "virtual" directories deep when calling a CSS file and it needs to handle that, using "/" is the easiest way around that so it would be a welcome decision to hand that with the Intellisense files.

I feel it's a safe assumption to assume that the site's root is the web root as in the instances it isn't, I would have thought the developer would be using another method...

Just a thought but could you hook into the value for the Casinni start up URL (by default the application name)? We always update that to the root when we're not using sub-directories/virtual directories.

Tim

# January 31, 2009 3:37 PM

Paul Crowder said:

I've found that I don't get IntelliSense on XML doc comments in the same file in which they appear (i.e. I put an XML doc comment in one function, then later in the file I use that function and I don't get IntelliSense provided by that XML doc comment).  Is there any plan to fix this soon?

# February 12, 2009 5:53 PM

WebDevTools said:

Hi Paul,

The next version of Visual Studio will give you XML doc comment enhanced tooltips in the JavaScript file you are editing.

# February 12, 2009 6:09 PM

梦想 said:

上个月,我在博客里宣布了微软将对jQuery提供支持。在过去的几个星期里,我们与jQuery开发团队合作,在Studio2008和VisualWebDeveloper2008Expres...

# April 26, 2009 12:15 PM

Craig Shoemaker said:

Dave Ward specializes in writing about ASP.NET, jQuery and ASP.NET AJAX. He is a contributing author

# June 22, 2009 9:59 AM
New Comments to this post are disabled
Page view tracker