This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 149001 - JavaScript Editor and Prototype( and jQuery )
Summary: JavaScript Editor and Prototype( and jQuery )
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: Macintosh All
: P2 blocker (vote)
Assignee: Torbjorn Norbye
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-02 19:54 UTC by urkman
Modified: 2009-02-27 14:26 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Scenario 1 - navigator shows class structure (27.21 KB, image/png)
2008-10-02 20:35 UTC, Torbjorn Norbye
Details
Scenario 2 - code completion shows properties for the prototype class (28.12 KB, image/png)
2008-10-02 20:36 UTC, Torbjorn Norbye
Details
Scenario 3 - Code completion still works, and "bar" property within class (83.85 KB, image/png)
2008-10-02 20:36 UTC, Torbjorn Norbye
Details
A object inside a "class" is not displayed under the "class", it is displayed beside the "class". (20.49 KB, image/png)
2008-10-02 21:00 UTC, urkman
Details
No correct CC inside the Class. (25.95 KB, image/png)
2008-10-02 21:01 UTC, urkman
Details
Correct CC outside of the "Class". (23.38 KB, image/png)
2008-10-02 21:02 UTC, urkman
Details
CC not working inside a Object using jQuery (17.47 KB, image/png)
2008-10-02 21:16 UTC, urkman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description urkman 2008-10-02 19:54:04 UTC
Hello,

I found some bugs in the JavaScript Editor, when using prototype:

1.) When I create a class
var foo = Class.create({
      bar: null,
      fooBar: function()
      {
      }
});
This Class is not shown as a Class in the navigator.

2.) Take the same Class:
var foo = Class.create({
      bar: null,
      fooBar: function()
      {
             this. // Here Code Assist is broken
      }
});
When you type "this." the Code Assist is broken. You get no function
or properties from the class.

3.) Take this Class:
var foo = Class.create({
      bar: {'foo': 1, 'bar': 2}, // Problem here...
      fooBar: function()
      {
             this. // Here Code Assist is broken
      }
});
Now the Class foo is still not shown in the Navigator, but the
property "bar" is shown as as an object in the Navigator. But not
under the class foo, but at the top level.

Stefan Sturm
Comment 1 Torbjorn Norbye 2008-10-02 20:35:13 UTC
I don't see the problems you're seeing.  which version are you using? (I see that it says version 6.5 in this version
field, but since the final release hasn't shippet yet -- is it 6.5 beta? Or something else).

I'll attach 3 small screenshots which show your three examples, all working for me.

A quick note on the navigator, as shown in example 1:
var foo = Class.create({})

JavaScript doesn't actually have classes - what we're doing here is creating a new object, and assigning it to a local
variable foo. We could continue to also assign it to many other local variables. The fact that there's a variable named
"foo" referencing our object with function properties doesn't really mean there is a class named "foo", but there is a
convention that "foo" is the name of this class.

However, NetBeans knows about many of these conventions - including prototype and several others - so it shows "foo" as
a class in the navigator (at least it's supposed to - it does for me, so we'll have to track down what's happening on
your side).   Note however that another convention is to name classes with capital letters (first letter uppercase), and
NetBeans uses this clue in many cases to treat something as a logical class instead of a variable. So if you for example
name your class "Foo" instead of "foo", the local variable "foo" is no longer shown in the navigator, and you see "only"
the "class".

Anyway, I'll attach the screenshots now so you can see what I'm seeing, including completion alternatives. Are you
reproducing these bugs with EXACTLY the code you submitted, or are these boiled down from a larger example? Can you show
me what you're seeing? Also, exact platform and version info might help. Also, can you try a brand new build?
  http://deadlock.netbeans.org/hudson/job/trunk/

We are now in high resistance for NetBeans 6.5 and we're only fixing high priority bugs. It would be great to validate
what you're seeing against what is going to be 6.5.
Comment 2 Torbjorn Norbye 2008-10-02 20:35:46 UTC
Created attachment 71067 [details]
Scenario 1 - navigator shows class structure
Comment 3 Torbjorn Norbye 2008-10-02 20:36:21 UTC
Created attachment 71068 [details]
Scenario 2 - code completion shows properties for the prototype class
Comment 4 Torbjorn Norbye 2008-10-02 20:36:53 UTC
Created attachment 71069 [details]
Scenario 3 - Code completion still works, and "bar" property within class
Comment 5 urkman 2008-10-02 21:00:28 UTC
Created attachment 71074 [details]
A object inside a "class" is not displayed under the "class", it is displayed beside the "class".
Comment 6 urkman 2008-10-02 21:01:37 UTC
Created attachment 71075 [details]
No correct CC inside the Class.
Comment 7 urkman 2008-10-02 21:02:26 UTC
Created attachment 71076 [details]
Correct CC outside of the "Class".
Comment 8 urkman 2008-10-02 21:08:43 UTC
Hello,

thanks for your answer. Here my answers:

1.) The var did the Job. Without it, you don't get the "Class" in the navigator. But, why I now have two foo entries in
the navigator? One simple foo and one for the "Class"?

2.) I attached a Screenshot showing, that a Object defined in this "Class" is displayed beside the "Class" and not under it.

3.) I attched 2 Screenshots showing the CC inside this "Class" and outside of it. I should complete "jQuery". Outside it
works, inside not.

Hope this time my description is better :-)

I'm using the latest dev build of 6.5 from today.

Greetings,
Stefan Sturm 

Comment 9 urkman 2008-10-02 21:16:28 UTC
Created attachment 71077 [details]
CC not working inside a Object using jQuery
Comment 10 urkman 2008-10-02 21:19:20 UTC
I attached one more screenshot (Bild 6) showing problem 3. This Time not using prototype Class.create, but this time
creating a simple Object.
Comment 11 Torbjorn Norbye 2008-10-02 21:50:28 UTC
I see what the problem is now.

First, Bild 1 - here the object inside your "class" is also treated as a class :-) That's why it shows up top level. I
used to only treat objects with -function- properties as classes. But that didn't work well because people would create
"classes" like "Point" with properties x,y, and would reasonably expect code completion etc. on these things. Thus, it
thinks "tmp" is a class with properties foo and bar.

Anyway, the main problem here is Bild 4 (and Bild 6, which is the exact same problem). Your Bild 5 shows the correct
behavior.

The problem is that when you are invoking code completion inside a function -call-, special rules apply. First, you
might have noticed the grayed out first item in the code completion. That's showing the function call you are inside.
This is usually helpful when the function has documentation. The documentation popup will tell you about the function
call you are making, such as what the parameter should be, and so on. The purpose here is that you can invoke code
completion when you're trying to fill out a function call and get some help about the surrounding call. 

It isn't obvious from this code that you are in function calls - but in Bild 4 you're in the "create" function call of
Class, and in Bild 6 you're in the "bind" function call from jQuery.   In any case, this is a scenario where you're
probably not thinking of the call you're making any more. I should probably refine this such that it only invokes call
completion if you are not inside a function scope within that call.

What does whether or not we are in a call have anything to do with this? Well, I actually have a special rule in there
that if we're making a function call, it's including less context in code completion - for example, it doesn't include
functions from the global function index. Obviously, however, global variables should be included. I disabled the code
which prunes the search in this way, and then code completion on jQuery works fine for both code snippets.

I haven't checked this in yet though. As I mentioned earlier we're in high resistance now, so I've gotta think about
this some more, check all the unit tests and possibly write some more for this scenario. But I feel I understand exactly
what the problem is, and how to fix it.
Comment 12 urkman 2008-10-02 22:09:57 UTC
Hello,

I hope you find the time to fix the bugs in Bild 4 and Bild 6 :-)

But one more to Bild 1:
I think the "tmp" Class should not be visible inside the navigator, because its scope is limited to the function using
the var keyword. It sould not be displayed, because it is not accessible outside the function and a simple variable (no
object) is not shown in the navigator. I think this is not consistent...
When the var keyword is missing the display is corrent and so it works for a simple variable.

And a second question: Why I have two foo Entries in the navigator?

Hope there will be a solution for the problems :-)

Greetings,
Stefan Sturm
Comment 13 Torbjorn Norbye 2008-10-03 01:27:46 UTC
I have fixed this in changeset 918959210c26.

(By "this" I'm referring to the main problem here, Bild 4 and Bild 6).

Regarding "Why I have two foo Entries in the navigator?" - I don't see two foo Entries in your pictures? Did you mean
"bar" ? If so, there is one instance for the local variable named "bar", the other corresponds to the Class that is
inferred from the right hand side of its assignment.

Regarding the "tmp" structure here: Yes, it's true that in this case, the variable is unused so it cannot "leak" outside
of this scope. But that's not true in general. Classes are often created inside other scopes, and even though the
original variable referencing it ceases to exist, the object itself is passed to other code. It would be good to do a
stronger analysis here to try to filter out cases where the object is truly transient. But I figure it's better to
include too much than too little. There is little harm in showing this object in the navigator, but not including
something people want would be worse.

I'm going to close this issue as fixed, since the main problem discussed here, the P2 issue regarding code completion
not working in certain contexts, is now resolved. If you can reproduce the problem with multiple "foo" variables, or if
you have further ideas for better class inference, please file those as separate issues.

Thanks for your report!
Comment 14 urkman 2008-10-05 16:43:21 UTC
Hello

thanks for the fix :-) Works great...

But I have one more point about the other problem.
Open the following file( It is an JabaScript Library ) and see that the navigator is completely overloaded and useless:
http://kevin.vanzonneveld.net/code/php_equivalents/php.namespaced.js

The displayed data is totaly confusing...

Greetings,
Stefan Sturm
Comment 15 Petr Pisl 2008-10-05 20:13:37 UTC
Please, file a separate issue for the latest problem. This issue is marked as fixed :).