locked
AMD pattern (requirejs) and Visual Studio intellisense

    Question

  • 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?

    Tuesday, July 17, 2012 5:38 PM

Answers

All replies

  • 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.

    • Marked as answer by Instriker Tuesday, July 17, 2012 8:23 PM
    Tuesday, July 17, 2012 8:23 PM
  • 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...

    Tuesday, July 17, 2012 8:42 PM
  • 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.
    Tuesday, July 17, 2012 10:15 PM
  • 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...

    Tuesday, July 17, 2012 10:47 PM
  • 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.
    Wednesday, July 18, 2012 1:49 PM
  • 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

    Saturday, August 18, 2012 5:19 AM