Visual Studio 2008 crashes when I open a JavaScript file? - javascript

Visual Studio Team system 2008 crashes without any error messages whenever I try to open a specific JavaScript file. I found this thread on social.msdn but installing the KB958502 hotfix didn't fix the problem.
Has anyone else experienced this and solved it?

Do you have PowerCommands for Visual Studio 2008 installed? If so, check this post for help:
FIX: PowerCommands for Visual Studio 2008 Crashes IDE
The exact same thing happened to me when I was opening some JavaScript files.

Since this is a different "answer" than my last, I am creating another post/entry.
I did experience this from time to time on a project I was on last year. I was using MochiKit as my toolkit, so take that into consideration.
Basically, I had some code like this in a file called common.js, which ran in the global scope:
if(typeof(DomEvent) == "undefined") {
DomEvent = {};
var domEventNames = [
"onabort", "onblur", "onchange", "onclick", "ondblclick", "onerror", "onfocus",
"onkeydown", "onkeypress", "onkeyup", "onload", "onmousedown", "onmousemove",
"onmouseout", "onmouseover", "onmouseup", "onreset", "onresize", "onscroll",
"onselect", "onsubmit", "onunload"
];
// forEach is a MochiKit function; functionality should be obvious
forEach(domEventNames, function(eventName) {
DomEvent[eventName] = eventName;
});
}
So, it basically dynamically builds an object assigned to the variable DomEvent and creates properties on that object that are have the same name as the value it holds (string representations of common browser events).
Now, I wanted Intellisense to help me with the API in other files, so in other files, I would have the following line in the top of the file:
/// <reference path="common.js"/>
That tells Visual Studio to "import" the API from that JavaScript file for use with Intellisense in the file this declaration is used in.
So I speculated that since the code in the common.js file, which I showed above, was building a global variable's value dynamically, Visual Studio was barfing on it. I felt fairly good about this hypothesis because the JavaScript code itself is sound, and Visual Studio would only crash if I used that XML comment to assist Intellisense. If I removed it, there wasn't a problem.
Hope that helps you or someone else.

Related

How to get hint for JS functions in HTML-Tags?

I searched for many hours for a solution and found nothing. So, I hope you can help me.
I using the latest version of Visual Studio Code (1.61.0) for Linux: In Atom or WebStorm was it possible, to type in the script tags of a HTML file the first letters of a function or writing the name of an object with a dot and the IDE opens a tool tip to show the possible functions in other JS files. But this don't work in VS Code. Also it is not possible to go to a function source via CTRL + Click. If I go with my mouse over the in HTML written function call, the tool tip displays "any".
My installed extensions (which have maybe influence with the problem):
HTML CSS Support
JavaScript and TypeScript Nightly
Visual Studio IntelliCode
Here are the files and a Screenshot of the "any" dialog. I hope someone knows a solution. Thank you!
index.html:
<script src="./js/hello.js">
document.getElementById("display-div").innerHTML = helloWorld();
</script>
js/hello.js:
function getMessage() {
return "Hi there...";
}

In Visual studio 2013, how can I debug my require()-ed dojo modules?

Today, I moved all my javascript code into pure dojo modules, so I could build them and all the modules they use into a single dojo.js file to reduce my page requests from hundreds down to just a handful. This is a wonderful improvement in my code and I need to keep doing this.
BUT:
Since I'm calling my javascript libraries through require() now, I'm having a heck of a time figuring out how to debug them. I can't just place a breakpoint in the .js file anymore and expect it to be hit. The breakpoint is a little empty circle that says
"this breakpoint will not be hit, no symbols have been loaded for this document"
To illustrate what I mean, suppose you have a library file named library.js
//this is library.js
define(["dojo/query"], function(query){
function LibraryFuncA(a, b)
{
return "" a + b;
}
return {LibraryFuncA: LibraryFuncA};
});
In my main cshtml file, I have to call it this way now:
<script>
require(["app/library"], function(lib){
var help = lib.LibraryFuncA("how do I ", "debug this?");
});
</script>
Anyway, this require call will fetch the app/library module from the cache if its in the built dojo file or it will fetch it from the server if I'm using the normal dojo file. But if I wanted to set a breakpoint in library.js to see what was going on in the VS2013 debugger when using IE, how would I do it?
Is there a way I can call LibraryFuncA without using require when it's concealed in the anonymous function that way?

JavaScript intellisense in Visual Studio only partially working

I'm seeing some strange behaviour with JavaScript intellisense in Visual Studio 2013 Express for Web. I followed all the advice I could google, and it's almost working perfectly.. but something to do with being inside or outside of a function seems to be affecting it. I am very new to JavaScript, so I might be missing something, but this doesn't make any sense to me:
Outside of a function it seems to work partially...
(I get one level of intellisense)
(but not two)
But inside of a function it works perfectly...
(I get all intellisense)
In a separate file, I get a similar problem, but down one function level...
(limited here)
(but everything here)
Any advice would be much appreciated!
OK I've looked through the code here's what I think.
Within Phaser.Game you have this code
/**
* #property {Phaser.GameObjectFactory} add - Reference to the Phaser.GameObjectFactory.
*/
this.add = null;
Because this is initially set to null I'm guessing Visual Studio will not be able to infer what type "add" will be since it is only determined at run time.
If add(...) was defined as Phaser.Game.prototype.add = function() { ... } or even within the function using this.add = function() { ... } I think you would see it in intellisense (this is normally how classes are built in Javascript). However I notice you are defining it dynamically later in the code like this from a factory:
this.add = new Phaser.GameObjectFactory(this);
Visual Studio isn't smart enough to know this is the definition of add(...) it should use for intellisense.
In the second example game is passed as an argument, and visual studio is not smart enough to work out what type this will be. Because Javascript is weakly-typed the argument could be a Game, but could also be an integer, boolean or anything else for that matter.

Visual Studio 2008 jQuery IntelliSense sporadically fails, restarting VS fixes

Right off the bat, this is not your standard "I can't get javascript IntelliSense to work in Visual Studio." For the record:
I'm using Visual Studio 2008
I have installed SP 1
I have installed the hotfix for -vsdoc.js documentation files KB958502
I am developing a suite of interrelated jQuery plugins to be packaged as resources in a class library. So within a directory, I have (as an example):
jquery-vsdoc.js
core.js
plug1.js
plug2.js
In core.js, I have the following at the top of the file:
/// <reference path="jquery-vsdoc.js" />
Then in each of the plug#.js, I have:
/// <reference path="jquery-vsdoc.js" />
/// <reference path="core.js" />
The IntelliSense works initially, even including the additions from core.js when working in the plugins. However, sometimes the slightest change, even adding and removing a space from the reference XML tags, or pressing Ctrl-Shift-J, results in the dreaded "Error updating JScript IntelliSense: Client-side script IntelliSense information was not generated due to an error in an external script reference." Except it was working with that external script reference just a second ago!
For the jquery-vsdoc.js, I am using Comment Version 1.3.2b (that's what it says in the file) from http://jqueryjs.googlecode.com/files/jquery-1.3.2-vsdoc2.js. I am omitting the version number from the file so that I don't have to change a bunch of references when it's inevitably updated.
So what could be the problem? Restarting Visual Studio is proving to be a horribly inelegant (and time-consuming) workaround.
Have you tried increasing the IntelliSense timeout?
By default, every IntelliSense request
is only allowed 15s to execute. This
is to prevent IntelliSense from
scripts with infinite loops. If you
have a large script or slower machine,
it may make sense to increase the
timeout limit. The timeout value
store within following registry keys
(depending on if your are using
Express or the full product). The
value is in milliseconds so choose
something greater than 15000.
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\HTML
Editor\JsFailsafeTimeout
HKEY_CURRENT_USER\Software\Microsoft\VWDExpress\9.0\HTML
Editor\JsFailsafeTimeout
Does closing and opening the file reset the state?
Open the task manager and watch the processes. Do you see a process called "typelibbuilder.exe" get started when you press Ctrl-Shift-J?
I'm trying to image what sort of problems might require a restart of VS. The processing of references (to which that message pertains) is done in a new and separate process every time you press Ctrl-Shift-J (unless processing has been disabled in which case you would see a different message). It almost sounds like the communication between VS and typelibbuilder or some other necessary component is failing.
In SP1, you shouldn't need to reference the "-vsdoc" files directly. If you reference "foo.js" and there is a "foo-vsdoc.js" file next to it, then VS will use the vsdoc version to generate intellisense. I doubt that is related to your problem though.
I know this isn't much consolation, but we've drastically improved performance and reliability of Javascript Intellisense in Visual Studio 2010. Beta1 is currently available to MSDN subscribers (although it is beta and there are still some bugs in it).
If you can get reliable repro steps, you could also file a bug report at http://connect.microsoft.com/.
I dont know if this will help you, but I've encountered the following bug in VS 2008 JS intellisense:
When adding jQuery as a reference in an external file, and then I update JS I get:
'XmlHttpRequest is undefined' on the line:
return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
It seems like the JS intellisense engine is actually executing some of the jQuery code (more than likely to inspect it so it can provide some more information about it). However it looks like window.ActiveXObject is null to the engine, and so it falls into the 'new XMLHttpRequest()' block - which also fails.
I hacked a workaround that breaks all browsers except IE - so not a good solution. My fix changes the following:
xhr: function()
{
// hack to fix VS 2008 intellisense... note this breaks any browser
// except IE
var objXhr = { open: function() { },
setRequestHeader: function() { }
};
return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : objXhr;
},
Now my intellisense works.
You may want to disable JavaScript intellisense in Visual Studio.
When SP1 is installed you can disable JavaScript intellisense.
Go to Tools, Options...
The Options dialog will show up.
Navigate to the following node in the left hand sided panel:
Text Editor :: JScript :: General
Disable the following options (in the group Statement Completion):
* Auto list members
* Parameter information

Visual Studio 2008 doesn't show my XML comments in JS files

function Submit_click()
{
if (!bValidateFields())
return;
}
function bValidateFields() {
/// <summary>Validation rules</summary>
/// <returns>Boolean</returns>
...
}
So, when I type the call to my bValidateFields() function intellisence in Visual Studio doesn't show my comments. But according to this it should. Should it?
I recall an issue where having turned off the Navigation Bar in VS stopped a lot of the JS intellisense from working properly. If you have it turned off, try turning the Navigation Bar on again and see if it helps.
Edit: You may also have to do Ctrl+Shift+J to force the IDE to update the intellisense.
Edit2: As #blub said, if there are any issues with the javascript, the intellisense can break. Visual Studio actually evaluates the javascript to create the intellisense, so if there are syntax errors it can fail and not build the intellisense completely, or at all.
The XML comments have to be inside the function, not above it.
In Visual Studio 2008, the XML comment information is only display for files referenced with a /// <reference... item.
Visual Studio 2010 will display XML comment information for functions in the file your are editing and for files you are referencing.
Did you try adding the /// <reference> comment at the top of the external library? I've run into this in the past and it resolved my issue.

Categories