jmbledsoe / angularjs-visualstudio-intellisense

Visual Studio extension providing statement completion for injected AngularJS components in JavaScript files.
MIT License
110 stars 22 forks source link

Controllers / Services in separate modules #4

Closed Templarian closed 10 years ago

Templarian commented 10 years ago

Some people place their controllers and services into ___Controllers and ___Services modules.

var mainApp = angular.module('mainApp', [
    'ngRoute',
    'mainControllers',
    'mainServices'
]);

var mainControllers = angular.module('mainControllers', []);

var mainServices = angular.module('mainServices', []);

Is there any global way you can map mainApp to either of these global modules? I tried for a while to modify your script to do it, but I'm lost.

Great work with this file, it is amazing! For now I just removed these modules.

Thanks, Austin

Templarian commented 10 years ago

I'm not at all familiar with how JS intellisense works, but I was thinking something like this, but have given up.

for (var i in window) {
    var m = null;
    if (m = i.match(/^(\w+)(Application|App)$/)) {
        intellisense.logMessage(i + '  ' + m[1]);
        // So... map mainApp to mainControllers I guess.
        intellisense.????(window[m[1] + 'Controllers'], window[i]);
        intellisense.????(window[m[1] + 'Services'], window[i]);
    }
}
jmbledsoe commented 10 years ago

It sounds to me like in your example, you want to map mainApp to map to a different variable, such as mainControllers or mainServices. I'm not inclined to enforce this convention. The mainApp variable should be what it was declared to be.

The code already contains logic to pick up global modules in window scope (see issue #3). I suggest declaring the mainControllers and mainServices modules before the mainApp module, but I'm not sure that will solve the problem. Please feel free to fork and add a test file (or multiple files) that demonstrate the problem you're having, and when I get a chance I'll take a look.

Templarian commented 10 years ago

I need to stop coding at 2am. Really bad oversight on my part.

Great work on this project, not defining the module first was the issue.

Thanks, Austin