locked
AMD pattern (requirejs) and Visual Studio intellisense RRS feed

  • 質問

  • Has anyone tried out requirejs for their metro apps? It works fine for me, but I have troubles with the IntelliSense when using it.

    I tryied to use the xml comments (as used by the base.js/ui.js) combined by the "/// <reference path=" pattern to include IntelliSense from files. Doing so, it works well for class defined in sync, but I don't get any IntelliSense for those defined into the AMD. For exemple, here is the AMD file:

    /// <reference path="ms-appx://Microsoft.WinJS.1.0.RC/js/base.js" />
    /// <reference path="ms-appx://Microsoft.WinJS.1.0.RC/js/ui.js" />
    
    (function () {
        "use strict";
    
        var MyClass = WinJS.Class.define(function () {
            /// <summary>
            /// Commment for MyClass
            /// </summary>
        });
    
        WinJS.Namespace.define("MyNamespace", { MyClass: MyClass });
    
        define([], function () {
    
            var MyClass2 = WinJS.Class.define(function () {
                /// <summary>
                /// Commment for MyClass
                /// </summary>
            });
    
            WinJS.Namespace.define("MyNamespace2", { MyClass2: MyClass2 });
            return MyClass2;
        });
    
    })();

    And how I try to use it :

    /// <reference path="TestIntelli.js" />
    
    (function () {
        "use strict";
    
        new MyNamespace.MyClass();   // IntelliSense working
        new MyNamespace2.MyClass2(); // IntelliSense not working
    })();

    Any idea why I lose intellisense it doesn't work, and how I could make it work?

    2012年7月17日 17:38

回答

すべての返信

  • I finally made it works using the Visual Studio extensibility described at http://msdn.microsoft.com/en-us/library/hh874692(v=vs.110).aspx.

    I used the project at https://github.com/jrburke/requirejs-intellisense which didn't work for me. So I made some changes to it so it supports all "overloads" of define and force a call to the module when called in define by Visual Studio intellisense. This way, the Namespace.define and Class.define are called and IntelliSense come back to life.

    • 回答としてマーク Instriker 2012年7月17日 20:23
    2012年7月17日 20:23
  • The RequireJS IntelliSense extension should work as long as you're primary file was referencing the module via a call to require as opposed to doing a /// <reference />.


    Code is never finished, only abadoned...

    2012年7月17日 20:42
  • Well, tell me if I'm wrong, but the primary file when I'm coding a module would be the AMD file. But there isn't any require in those files, only defines, so the processing never occurs when writing a module.
    2012年7月17日 22:15
  • Yep, you're right. I was referring to the module-consumption code (which would have a call to require) since that was what your original post was highlighting.

    Code is never finished, only abadoned...

    2012年7月17日 22:47
  • I agree, I simplified my sample code too much before posting. My original idea was really to get the IntelliSense working inside the callback of requires and defines methods.
    2012年7月18日 13:49
  • That sounds great!  Could you please share your changes or submit a pull request on GitHub?  I'm encountering the same issues and it's not clear how to make the same changes you did based on your comments.

    http://orand.blogspot.com

    2012年8月18日 5:19