What should I do to obtain javascript intellisense

2020-03-26 14:06发布

问题:

I have multiple javascript files and they have their own functions. If I make reference one of them to inside any of them, it doesnt see its functions if the function is not prototype. What is logic inside the Intellisense ?

I want to use Splash function with Intellisense feature below, how can I do that ?

//My.js
/// <reference path="Test.js" />

.

//Test.js
NameSpace.prototype.UI = new function () {

    this.Splash = function (value) {
        try {
            if (value == 1) {
                $('#splash').css('height', $(document).height());
                $('#splashContent').css('top', $(window).height() / 2);
                $('#splash').fadeIn();
                $('#splashContent').fadeIn();
                setTimeout("SF.UI.Splash(0)", 3000);
            }
            else if (value == 0) {
                $('#splash').fadeOut(1000);
                $('#splashContent').fadeOut(1000);
            }
            else if (value == 3) {
                $('#splash').css('height', $(document).height());
                $('#splashContent').css('top', $(window).height() / 2);
                $('#splash').fadeIn();
                $('#splashContent').fadeIn();
            }
        } catch (e) {
            Splash(0);
        }
    }
}

回答1:

JS Intellisense is flaky at best. Despite all those articles, in my experience, it doesn't work as advertised. I would suggest:

  • Make sure all your JS files are in the same project (making ti work across projects is even trickier).
  • Make sure /// <reference path="Test.js" /> is the very first line in JS.
  • Make sure there are no errors in the Test.js file (run JSLint on it to be sure) or use the vsdoc approach.
  • Look at the Output tool window to see if it contains any errors related to updating intellisense. This will help you troubleshoot and remove errors in your referenced JS file.

Alternative to create a Test-vsdoc.js file (this way, even if your main JS file has errors, it would not cause intellisense to fail) :

//Test-vsdoc.js
NameSpace.prototype.UI = new function () {

    this.Splash = function (value) {
    /// <summary>This is my function summary</summary>
    }
}

VS would automatically include it next time you restart the IDE (or try a force update Ctrl+Shift+J)



回答2:

Assuming that is the actual contents of your js file, including the //My.js comment, then that is your problem right there.

/// <reference comments must be at the very top of the file, before any other content, otherwise they will not work.

Side note, did you know there is a code snippet for that reference? its ref, then tab tab. Also you can drag / drop a file and get the comment.

Once you have your references done, you can force VS2010 to refresh your js comments by pressing Ctrl+Shift+J while editing the .js file