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

No intellisense when declaring function for angular components in IFFE #22

Closed ChristianWeyer closed 9 years ago

ChristianWeyer commented 9 years ago

Maybe this is related to the note from the README ("").

Our common pattern for registering functions with angular goes like this - here for a a service: (function () { "use strict";

/**
 * @constructor
 */
function Foo() {
    this.bar = function() {

    }
}

app.module.service('foo', Foo);

})();

When I then use foo in my BarController: (function () { "use strict";

/**
 * @param $scope
 * @param {Foo} foo
 * @constructor
 */
function BarController($scope, foo) {

}

app.module.controller('barController', BarController);

})();

In this case I do not get Intellisense for foo - in WebStorm this works, BTW. Thanks!

fhrn71 commented 9 years ago

I have the same issue. Using IFFE to build angular applications is really promoted. So I can imagine more developers will run into the same issue. It will be great to have intellisense for it.

jmbledsoe commented 9 years ago

That's odd. I use IIFE in every AngularJS project I build and I can get Intellisense. You definitely need a _references.js file that is set up similarly to how you have your scripts included in your outer HTML page. If that's not in place then you won't get Intellisense.

fhrn71 commented 9 years ago

Hi John,

I spent this evening a lot of time to get rid off the issues with the intellisense. First I check a lot of stuff to check all javascript needed for intellisense is loaded in the correct order. I copied the example with the BarController as given by ChristianWeyer at the first post in the thread.

I check the existence of the _references.js file and it was there. In addition I tested the intellisense for it with a plain function defined in one of the referenced files and that works well. The references to the angular works, too. E.q. angular.module().provider gives the help for the provider. This indicates the angular.intellisense.js is loaded. But I was still not able to got intellisense for the injected dependencies like services and constants. In the BarController example is that $scope and foo.

I digged somewhat in the angular.intellisense.js and turn on the log to level VERBOSE and got the next output: 02:25:03.4789: Start AngularJS_VisualStudioIntellisense 02:25:03.4789: Tracking module "ng". 02:25:03.4789: Tracking module "ngLocale". 02:25:03.4789: Calling "angular.module" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "my", 02:25:03.4789: } 02:25:03.4789: Tracking module "my". 02:25:03.4789: Calling provider function "controller" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "BarController", 02:25:03.4789: 1: $FUNCTION, 02:25:03.4789: } 02:25:03.4789: Creating instance of controller "BarController". 02:25:03.4789: Creating instance of controller "BarController" returned the following: 02:25:03.4789: { 02:25:03.4789: $isExceptionObject: true, 02:25:03.4789: } 02:25:03.4789: Calling all functions on the following component: 02:25:03.4789: { 02:25:03.4789: $isExceptionObject: true, 02:25:03.4789: } 02:25:03.4789: Calling "angular.module" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "my", 02:25:03.4789: } 02:25:03.4789: Calling provider function "controller" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "BarController", 02:25:03.4789: 1: $FUNCTION, 02:25:03.4789: } 02:25:03.4789: Creating instance of controller "BarController". 02:25:03.4789: Creating instance of controller "BarController" returned the following: 02:25:03.4789: { 02:25:03.4789: $isExceptionObject: true, 02:25:03.4789: } 02:25:03.4789: Calling all functions on the following component: 02:25:03.4789: { 02:25:03.4789: _$isExceptionObject: true, 02:25:03.4799: }

As you can see the script breaks on creating the instance of the controller. Hope you have any suggestions. Van: John Bledsoe [mailto:notifications@github.com] Verzonden: maandag 27 april 2015 19:03 Aan: jmbledsoe/angularjs-visualstudio-intellisense CC: fhrn71 Onderwerp: Re: [angularjs-visualstudio-intellisense] No intellisense when declaring function for angular components in IFFE (#22)

That's odd. I use IIFE in every AngularJS project I build and I can get Intellisense. You definitely need a _references.js file that is set up similarly to how you have your scripts included in your outer HTML page. If that's not in place then you won't get Intellisense.

— Reply to this email directly or view it on GitHubhttps://github.com/jmbledsoe/angularjs-visualstudio-intellisense/issues/22#issuecomment-96741456.

jmbledsoe commented 9 years ago

All I can suggest at this point is that you upload/email your project (or a minimal version that demonstrates the issue) I'm willing to take a look but apart from a project from which I can reproduce the issue there isn't anything I can do.

I'm certainly grateful for your interest in the project and I hope we can get your issue solved. On May 1, 2015 8:29 PM, "fhrn71" notifications@github.com wrote:

Hi John,

I spent this evening a lot of time to get rid off the issues with the intellisense. First I check a lot of stuff to check all javascript needed for intellisense is loaded in the correct order. I copied the example with the BarController as given by ChristianWeyer at the first post in the thread.

I check the existence of the _references.js file and it was there. In addition I tested the intellisense for it with a plain function defined in one of the referenced files and that works well. The references to the angular works, too. E.q. angular.module().provider gives the help for the provider. This indicates the angular.intellisense.js is loaded. But I was still not able to got intellisense for the injected dependencies like services and constants. In the BarController example is that $scope and foo.

I digged somewhat in the angular.intellisense.js and turn on the log to level VERBOSE and got the next output: 02:25:03.4789: Start AngularJS_VisualStudioIntellisense 02:25:03.4789: Tracking module "ng". 02:25:03.4789: Tracking module "ngLocale". 02:25:03.4789: Calling "angular.module" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "my", 02:25:03.4789: } 02:25:03.4789: Tracking module "my". 02:25:03.4789: Calling provider function "controller" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "BarController", 02:25:03.4789: 1: $FUNCTION, 02:25:03.4789: } 02:25:03.4789: Creating instance of controller "BarController". 02:25:03.4789: Creating instance of controller "BarController" returned the following: 02:25:03.4789: { 02:25:03.4789: $isExceptionObject: true, 02:25:03.4789: } 02:25:03.4789: Calling all functions on the following component: 02:25:03.4789: { 02:25:03.4789: $isExceptionObject: true, 02:25:03.4789: } 02:25:03.4789: Calling "angular.module" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "my", 02:25:03.4789: } 02:25:03.4789: Calling provider function "controller" with the following arguments: 02:25:03.4789: { 02:25:03.4789: 0: "BarController", 02:25:03.4789: 1: $FUNCTION, 02:25:03.4789: } 02:25:03.4789: Creating instance of controller "BarController". 02:25:03.4789: Creating instance of controller "BarController" returned the following: 02:25:03.4789: { 02:25:03.4789: $isExceptionObject: true, 02:25:03.4789: } 02:25:03.4789: Calling all functions on the following component: 02:25:03.4789: { 02:25:03.4789: _$isExceptionObject: true, 02:25:03.4799: }

As you can see the script breaks on creating the instance of the controller. Hope you have any suggestions. Van: John Bledsoe [mailto:notifications@github.com] Verzonden: maandag 27 april 2015 19:03 Aan: jmbledsoe/angularjs-visualstudio-intellisense CC: Frans Harinck Onderwerp: Re: [angularjs-visualstudio-intellisense] No intellisense when declaring function for angular components in IFFE (#22)

That's odd. I use IIFE in every AngularJS project I build and I can get Intellisense. You definitely need a _references.js file that is set up similarly to how you have your scripts included in your outer HTML page. If that's not in place then you won't get Intellisense.

— Reply to this email directly or view it on GitHub< https://github.com/jmbledsoe/angularjs-visualstudio-intellisense/issues/22#issuecomment-96741456>.

— Reply to this email directly or view it on GitHub https://github.com/jmbledsoe/angularjs-visualstudio-intellisense/issues/22#issuecomment-98268805 .

ghost commented 9 years ago

I'm having the same problem in a Tools for Apache Cordova project in Visual Studio 2015. The one that I mentioned in issue #29.

In this project I have all of my services, directives and controllers in separate files. There is no _references.js file, but none is needed - I do get intellisense when I do the following (despite the lack of annotation):

angular.module('myapp').controller('SomeCtrl', function (AlertService) {   
  AlertService.intellisenseWorksHere();
});

(AlertService resides in a separate file). However, if I do the following, I get no intellisense:

/** @ngInject */
function SomeCtrl(AlertService) {
  AlertService.doesNotGetIntellisenseHere();
}
SomeCtrl.$inject = ['AlertService'];
angular.module('myapp').controller('SomeCtrl', SomeCtrl);

I'll be glad to send you a copy of my project, but it is a private project, so I can't attach it here.

ghost commented 9 years ago

I have also tried using jsDoc @param {AlertService} AlertService style comments and I also tried adding a _references.js file to my project but neither worked.

ghost commented 9 years ago

I got this working by making a change similar to the one mentioned in issue #27. Importing my services module into my controllers module fixed everything.

  angular.module('myapp', [
    'ionic',
    'ngCordova',
    'myapp.controllers',
    'myapp.services'
  ])
    .config(configureViews)
    .run(runApp);

  angular.module('myapp.controllers', [
    'ionic',
    'ngCordova',
    'myapp.services' // adding this line fixed my issues.
  ]);

  angular.module('myapp.services', [
    'ionic',
    'ngCordova'
  ]);

My observation was in correct before. Intellisense was actually working for all classes in the same module (despite being in separate files). So my AlertService had no problem getting intellisense for my LocalFileService, but my SomeCtrl controller could not get it for AlertService. Once I saw that, I figured out the problem.

jmbledsoe commented 9 years ago

@waynebloss I believe the module issue has the same root cause as what is being tracked in #27. I'm closing this issue since I believe that one covers this problem.

@ChristianWeyer and @fhrn71: if your problems aren't yet resolved then please request reopen and point to a sample project.