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

IntelliSense breaks for a module when you're in the file that first defines that module #8

Closed jmatthiesen closed 10 years ago

jmatthiesen commented 10 years ago

A hard one to summarize in words, but perhaps a code example will make it clear. I have a case here where IntelliSense fails for dependencies defined within the same module, but in separate files. Here's the scenario that breaks

  1. Create two files common.js and logger.js
  2. In your web projects _references.js, make sure common.js & logger.js are both included (along with Angular itself, and this AngularJS IntelliSense extension)
  3. Within common.js, create the common module and use it to create a common factory
  4. Within logger.js use the common module and create a logger factory on that module
  5. Back within common.js, update the common factory to depend upon the logger factory

IntelliSense for logger. doesn't work in common.js, because the line of code that creates the common module within that file resets the module and loses that logger is ever defined on it.

common.js

(function () {
    'use strict';

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

    commonModule.factory('common', function (logger) {
        logger. // No IntelliSense, right here
        return { foo: true }
    });
})();

logger.js

(function () {
    'use strict';

    var commonModule = angular.module('common');

    commonModule.factory('logger', function (common) { return { log: true } });
})();

In the first example, if you change the module definition to var commonModule = angular.module('common'); it works fine.

jmbledsoe commented 10 years ago

This is still an issue in the latest release. I have a couple of hackish ideas of how to fix it, but don't want to explore those until we talk further about the VS JavaScript editor.

jmbledsoe commented 10 years ago

Fixed in 38f04df37050bd868d6979a7f87ce4a35ac30b16.