Code assist to work for an instance variable accross methods

Feature requests
Post Reply
patrickbrosset
Posts: 5
Joined: Mon Sep 29, 2008 10:41 am

Code assist to work for an instance variable accross methods

Post by patrickbrosset » Mon Sep 29, 2008 10:59 am

Hi all,

I've been investigating the use of Spket as a JS editor in Eclipse for my company's needs. I find it very very powerful and adapted to what we do except for one thing that appears to be missing:

Remembering the type of a given variable within the constructor and methods of a class.

Consider the code below:

Code: Select all

/**
 * @include "User.js"
 * @class
 */

var myGlobalVar = new User();

function MyClass() {
	this.prop = new User();
	this.prop.setName("test"); // code assist works within this scope
}

MyClass.prototype = {
	method1 : function() {
		var n = this.prop.getName(); // no code assist here
	},
	method2 : function() {
		var a = this.prop.getAge(); // no code assist here
		var a2 = myGlobalVar.getAge(); // code assist works on global
	}
}
In the first comment at the top, I include a reference to a JS file where the User class is defined.
The I define a class. In its constructor, I instantiate a new User object and assign it to a instance property: this.prop.

So far, everything is great, the code assist gives me access to all the properties and methods on this.prop as long as I am inside the constructor of my class because it knows the type of this.prop is User.

As soon as I try to call a method on this.prop outside of the scope of my constructor function, in method1() for instance, Spket doesn't show me the correct code assist anymore.

It seems that Spket doesn't remember the type of a variable outside the scope it was created in, even if the variable itself is accessible on the this keyword.

Note that it does work however for global variables.

Tell me if there is a way already to do this that I didn't know of, or if this is already in the plan somewhere.
If not, adding such a feature would really great!

Thank you.
Patrick

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Post by eric_suen » Mon Sep 29, 2008 4:13 pm

It seems a bug, I will fix it in next version.

patrickbrosset
Posts: 5
Joined: Mon Sep 29, 2008 10:41 am

Post by patrickbrosset » Mon Sep 29, 2008 8:26 pm

Thanks a lot for the reactivity.
Looking forward to this new version.

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Post by eric_suen » Wed Oct 01, 2008 10:21 am

This bug has been fixed in version 1.6.16, thank for report this issue.
Last edited by eric_suen on Wed Oct 01, 2008 10:27 am, edited 1 time in total.

patrickbrosset
Posts: 5
Joined: Mon Sep 29, 2008 10:41 am

Post by patrickbrosset » Wed Oct 01, 2008 10:23 am

Thanks a lot.
I'll have a look at version 1.6.16 whenever it is available.

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Post by eric_suen » Wed Oct 01, 2008 10:30 am

version 1.6.16 is available already.

cafebabe
Posts: 14
Joined: Tue Mar 31, 2009 9:31 pm

Post by cafebabe » Wed Apr 08, 2009 10:51 pm

Code: Select all

Ext.ux.Test = Ext.extend(Ext.Panel,{
	fun1 : function() {
		this.prop1 = 'some val';
	}
	,fun2 : function() {
		this.prop1.length();  // no code complete on this. to see prop1
	}
})
is there a way to get code complete for local variables such as prop1 without having to define them explicitly as a property like fun1 and fun2? I notice that prop1 does show up as a property of Ext.ux.Test in the outline

patrickbrosset
Posts: 5
Joined: Mon Sep 29, 2008 10:41 am

Re: Code assist to work for an instance variable accross met

Post by patrickbrosset » Tue Jul 17, 2012 11:41 am

Consider the following code:

Code: Select all

function MyClass () {
  /**
   * @type {Test}
   */
  this.prop = new Test("e");
  this.prop.getSomething();  // code assist works here
};
MyClass.prototype.method1 = function () {
  this.prop.getSomething(); // code assist doesn't work here, no drop-down menu proposing the getSomething method from the Test class
}
So, what was fixed in the version mentioned above doesn't seem to be fixed for me (running version 1.6.23).

Also, I found out that:

Code: Select all

function MyClass () {
  /**
   * @type {Test}
   */
  this.prop = new Test("e");
  this.prop.getSomething();  // code assist works here
};
MyClass.prototype = {
  method1 : function () {
    this.prop; // code assist doesn't work here at all, this.prop is not proposed.
  }
};
Turns out it seems you have to use the form class.prototype.method rather that class.prototype = {method}.
Any idea why this is behaving this way?

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Re: Code assist to work for an instance variable accross met

Post by eric_suen » Tue Jul 17, 2012 4:13 pm

Both works fine for me, what's your JavaScript profile? If it's the profiles provide by app itself(has different background), then you need create a custom JavaScript profile and use that as default profile. you can crate profile via menu Window -> Preferences..., the choose Spket -> JavaScript Profiles, create a new one and set it as default, you don't need add any library if you don't want to.

patrickbrosset
Posts: 5
Joined: Mon Sep 29, 2008 10:41 am

Re: Code assist to work for an instance variable accross met

Post by patrickbrosset » Wed Jul 18, 2012 6:32 am

Ok thanks a lot. I'll try that.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests