How to solve JavaScript IntelliSense problems in VS2010

How to solve JavaScript IntelliSense problems in VS2010

  • Comments 4

VS2010 should support all of the VS2008 JavaScript functionalities as shown in Scott Guthrie’s VS2008 JavaScript IntelliSense blog.  It includes:

1. Basic type inference

2. IntelliSense from referenced external JavaScript libraries

3. IntelliSense from XML comments for functions, parameters and return types

4. Calling web services using ASP.NET AJAX

 

Additionally, VS2010 RTM had some improvement, including:

1. IntelliSense when manipulating browser objects

2. Dynamic generated variable IntelliSense

3. Default JavaScript snippets within IntelliSense to help you code faster

Scott Guthrie has a brief blog covering some of these.

 

Due to the dynamic feature of our JavaScript engine, we may run info conflicts between XML commented return types and inferred return types in some cases.  For example:

1. Dynamically generated IntelliSense will override the XML commented return types. 

    For example, the following code snippet shows string IntelliSense, instead of number IntelliSense:

image

This may lead to a confusing result sometimes.  The best way to solve this is to create a vsdoc commenting file, and remove the conflicting return statement from such functions, just like jquery-1.4.1-vsdoc.js in VS2010 RTM:

image 

2. Sometimes, the JavaScript engine may meet an exception internally during dynamic function execution in the current or referenced document.  The cause could be a JavaScript function syntax error, logic bug, or the VS2010 JavaScript engine bug. The corresponding IntelliSense at this time will be shown as a simple object or not shown at all.  To support good IntelliSense behavior in this case, try build a VSDoc file, add XML comments and remove the offending code.

 

Some useful links:

Format of JavaScript doc comments

VSDoc file look up orders

 

Thanks

Xinyang Qiu

Web Platform and Tools

Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
  • I have an odd setup (because I don't do things "normal") that's causing me to not have intellisense that I'd LOVE to have.  I can work around it in .js files, but the <script...> tag in .html doesn't work right for me.

    What works:

     <script src="d:\Company\scripts\SharedScript.js">

    what doesn't work:

     when editing "d:\Company\MyProjects\MyApp\MySite\MyPage.htm", using:

     <script src="../../scripts/SharedScript.js">,

    The *reason* this isn't working is because I actually have two projects ("existing web sites") in the solution:

    the project "d:\Company\Scripts" manages scripts that are shared amongst multiple developers,

    and "d:\Company\MyProjects" manages my personal collection of responsibilities.

    So, the relative path from "D:\Company\MyProjects\MyApp\MySite" fails because the relative path traces to a folder before the projects "base folder"

    I have a couple of options I'd like to see to allow fixing this, but I'm sure you all can come up with your own, as well:

    * When in the editor, treat relative paths as relative *on the filesystem* instead of *in the project" (maybe make this a configuration option?)

    * Allow [/// <reference path="d:\Company\Scripts\SharedScript.js"/>] within a <script> tag:

     <script language="javascript" type='text/javascript">

     /// <reference path="d:\Company\Scripts\SharedScript.js"/>

     var testIntellisense = external.fromShared.doSomething();

     </script>

    * Add a "reference" attribute to the <script src=""> tag:

     <script src="../../scripts/SharedScript.js" reference="d:\Company\Scripts\SharedScript.js"></script>

    * Add a configuration option for the javascript editor that pre-loads javascript files for intellisense

     (I can see how this might cause other problems, though - like "what happens when the included script is the same as the pre-loaded script?"  ... but I'm sure there are options to resolve that.)

    OK...enough of me rambling.  If anybody would like to get in touch with me, please e-mail!  (I'll check back here to see if there's feedback here, as well.)

    Thanksf or the patience to read all this!

  • theGleepWork - The issue with your exapmle is your trying to traverse a folder path using URL notation (forward slashes). If you change your src path to use back slashes, IntelliSense works. However this might cause you problems at runtime. You can get the "best" of both worlds by doing something like this:

    <% if(false) { %>

    <script type="text/javascript" src="..\..\Scripts\shared.js"></script>

    <% } else { %>

    <script type="text/javascript" src="../../Scripts/shared.js"></script>

    <% } %>

    <script type="text/javascript">

       // IntelliSense for stuff in shared.js works fine here now

    </script>

  • theGleep@work - The issue in your case is you're using URL travesal syntax (forward slashes) to try and find a file path. If you change it to use backslashes IntelliSense will work, but you don't really want that to be rendered to the browser. You can get the "best" of both worlds doing something like this:

    <% if(false) { %>

    <script type="text/javascript" src="..\..\Scripts\shared.js"></script>

    <% } else { %>

    <script type="text/javascript" src="../../Scripts/shared.js"></script>

    <% } %>

    <script type="text/javascript">

       // IntelliSense for stuff in shared.js works fine here now

    </script>

    Hope this helps.

  • Thanks, Damian - that did the trick!  And since our web-app is IE-only, I can just use the file-path syntax, and it's coverted by the browser...no asp tricks needed.  

    Thanks for the tip!

Page 1 of 1 (4 items)