What should I do to obtain javascript intellisense for my own js library in Visual Studio

僤鯓⒐⒋嵵緔 提交于 2020-01-29 21:03:32

问题


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



来源:https://stackoverflow.com/questions/6452760/what-should-i-do-to-obtain-javascript-intellisense-for-my-own-js-library-in-visu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!