-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
missing completions or scope issue #184
Comments
Yes, you'll need the I don't think there's a lot that can be done about this problem. |
I see, that is too bad since in any backbone project most of the code is laid out like the snippet above. I wonder if one could introduce a special rule that looks for extend() blocks and in that case bind 'this' accordingly. Even if so I guess it wouldn't find its way in the tern code base since it's rather specific. Nonetheless I wish I could somehow get some sort of semi-solution since this reduces the usefulness of tern quite a bit for me :-( |
Try with the attached patch. It uses a different technique for categorizing property functions as methods, which should also work in your case. At least it works in the new test case (see patch) which tries to emulate that case. |
Thanks i will test this properly shortly. At first glance it seems like if I do a completion on "this" inside of function "foo" (referring to the test case above) it will only find properties of "this" that are being accessed within the scope of the function "foo" itself. |
This does indeed work fine when I try it with the online demo. It does however not work in vim. Doesn't make much sense does it ? I'm on HEAD (6e44bf0) just like the demo. In vim the only completions I will get on "this" are properties added to this inside the respective scope. Should I file a bug in tern for vim ? |
I believe this is because the online demo coincidentally includes underscore.js. If I I have a rough integration test that shows this working at |
I have always had underscore in my loadEagerly section. Still, no dice. I'm a bit at loss what's going on here. @clausreinke do you have any ideas on this ? suggestions ? |
I should have used exactly the same test code right away - sorry. The code above works, but it does not work in most parts of my production code in my current project. I am trying to distill what is actually confusing tern but still haven't quite figured it out yet. |
Sorry for spamming on this issue but it is driving me nuts. I just couldn't figure out why in simple examples everything would work but in real life production code it wouldn't. Now I just realised that there is some screw up with number of lines .. Completions on 'this' inside the foo function in this code will work fine : Huh = Backbone.View.extend({
foo: function () {
}
}); However if you add like 250 line comment lines you won't get any completions. Neither inside the foo function Huh = Backbone.View.extend({
/*
*
*
... lots of more comment lines ..
*
*/
foo: function () {
this.rend
}
}); Tried that in vim and with the online demo .. o__O" Someone tell me my brain is just stuck please. |
Could you put the actual file that fails for you in a gist or paste service somewhere? I just tried to reproduce what you did from your description, but things still work fine. |
I tested it again with the online demo: It is rather weird. Here is the code: https://gist.github.com/gilligan/5960234 and here is the backbone library http://backbonejs.org/backbone.js I get completions (on 'this.') on the very first attempt but never again after that. When I remove the comment block it works reliably each time. |
Thanks for the test case! I'm not sure how it differed from mine (this is pretty much exactly what I remember typing in yesterday), but it does reproduce the issue. The problem is that for big buffers, only a part is sent to the server per request (except for the first request, which is why you saw it work the first try). The error-tolerant parser can make something out of most fragments, but in this case it really gets very confused, causing the analyzed code to be pretty much nonsense, and thus preventing meaningful analysis. There are several other problems with the way file fragments are currently created. I'll look into creating a new algorithm for that. |
Please try again with attached commit. The problem was not so much in the way the file fragment was created, but in the way it was interpreted. I've added special code handling function defined as properties of huge object literals, since that's a common pattern. |
Sorry I am really slow responding to this. I did some tests in the online demo and that appears to work. I just noticed that it's broken in the vim plugin though. var Test = Backbone.View.extend({
foo: function() {
}
}); If I try to complete anything on 'this.' in the foo scope I will get a 'Pattern not found' error in the command line and no completions. This has to be a different problem though since its working with the online demo. Should I create an issue for the vim plugin ? |
I've never seen a "Pattern not found" error -- not sure where that might be coming from. |
@clausreinke ? any ideas what's going ? |
"Pattern not found" here just means that no matching completions were found, I think. Were those 4 lines the whole test case (no plugins, .tern-project, or such)? |
I created a tiny test project for this : https://github.com/gilligan/tern-vim-test And of course it works just fine... The problem remains in my real world, big javascript app at work but i'm aparently having troubles extracting the core issue into a small test case. I will try some more and let you know. |
Well it seems like i figured it out now. The problem lies in using backbone-0.9.2 : https://github.com/gilligan/tern-vim-test/tree/backbone-092 (which i happen to use at work). When I use backbone 0.92 the completion works exactly once and on the next calls 'this.' won't yield any results (Except for any previous occurrences of 'this' properties that already appear in the current scope). |
Eventually it would be nice to have an accurate |
Following test scenario: Use the http://ternjs.net/doc/demo.html and add http://backbonejs.org/backbone.js as a new file. Then add another file with the following contents:
Invoking completions on the newly created Test works fine and includes (apart from all the properties from Backbone.View) the functions foo, bar and the something property.
Inside the scope of either foo() or bar() however tern does not find any properties at all when invoking completion on "this."
The text was updated successfully, but these errors were encountered: