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 inside local functions #6

Closed Wintermoose closed 9 years ago

Wintermoose commented 10 years ago

Hi, I was playing with the code today and I found out that the intellisense doesn't seem to work on the controller's injected parameter, when referred inside local functions. I.e. reference to constant inside someProviderFunction (line 26 of the test file) doesn't resolve.

When I tried similar simplified test (calling function with parameters explicitly) it works, as well as when the someProviderFunction is called inside the controller.

Do you know what might be causing the problem? Is there any workaround? It seems quite limiting, given the frequently used pattern $scope.someFunction = function()...

Thanks

jmbledsoe commented 10 years ago

I'm somewhat aware of what is causing the problem, but I'm not aware of any workaround. It seems that to get Intellisense to work, the _intellisense.js script needs to "execute" each function in your file, which is how it determines Intellisense information. Since the _intellisense.js script doesn't know about the functions you assign to the $scope object, it doesn't execute them, and therefore no Intellisense.

I believe that the _intellisense.js script could be modified to scan the properties of objects returned from factory functions, and when it finds a function, go ahead and call it. I don't know if this would work through, and frankly it's an exercise that I'm going to leave to someone forking the file.

Wintermoose commented 10 years ago

I kind of guessed that's the case, I just thought there is something extra at play. When I create basic function A (and try to assign it to variable, just to be more complex), the function defines local functions inside, and then I call A with some parameters, the parameters resolve correctly even in the local functions which are never called.

But there seems to be some additional rules for calling the stuff between sources, or maybe the order in which they get called, because if I place the call to the function somewhere else (into intellisense.js), it won't help (in addition, the function seems to be called from somewhere - visual studio? - without parameters).

Just for reference, this is my test fn:

var q= function myq(dt) {
    dt.getHours();
    intellisense.logMessage("I was called with: " + JSON.stringify(dt));
    //dt.
    window.expandSomething = function(q) {
        function a() {
            function b() {
               //dt.
            }
        }
    }
}
// q(new Date());
jmbledsoe commented 9 years ago

I actually have a prototype of this feature worked out, but it's fickle. Since the Intellisense engine needs to execute a function in order to determine how to complete statements in the function, I have it worked out to execute the "default code path" of every function accessible from an AngularJS component. This is better than the current implementation and I will update when I get the new version committed.

jmatthiesen commented 9 years ago

@jmbledsoe I may be able to help out here some - I work in the Microsoft Visual Studio team that builds the JavaScript editor. Feel free to email me: jomatthi -at- microsoft.

jmbledsoe commented 9 years ago

I've updated the _intellisense.js file and it now calls more local functions, but not all of them. It seems that the VS gathers statement completion information by actually calling the JavaScript methods in a file (or referenced files). Therefore, I changed the _intellisense.js file to actually call every function exposed by each AngularJS service, and then to call any functions exposed by return values of those functions, and so forth. This, in addition to some AngularJS-specific function calls documented in the README, catch many private functions, but those functions must be called in order to get statement completion. I'll leave the issue open, as I'm hopeful that I'll be able to garner some more information about the VS JavaScript editor from @jmatthiesen.

jmatthiesen commented 9 years ago

After some experimenting, it looks like this new code is causing some timeouts. @jmbledsoe do you have some test cases in the project that were fixed as a result of this code? If so, can you point me at them so I can see if changes in the algorithm fix those cases, or break them? If not, can you put together some test cases that didn't work before this code was added?

jmbledsoe commented 9 years ago

I don't have test cases right now, but the issue surrounded statement completion for complex return types of service functions. I will put some tests together over the weekend and look into setting a recursion limit. On Jan 21, 2015 8:29 PM, "Jordan Matthiesen" notifications@github.com wrote:

After some experimenting, it looks like this new code is causing some timeouts. @jmbledsoe https://github.com/jmbledsoe do you have some test cases in the project that were fixed as a result of this code? If so, can you point me at them so I can see if changes in the algorithm fix those cases, or break them? If not, can you put together some test cases that didn't work before this code was added?

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

jmbledsoe commented 9 years ago

This issue is atrophied unfortunately, so I am closing. I believe we're past the timeouts with the most recent version.