Page 1 of 1

Code assist to work for an instance variable accross methods

Posted: Mon Sep 29, 2008 10:59 am
by patrickbrosset
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

Posted: Mon Sep 29, 2008 4:13 pm
by eric_suen
It seems a bug, I will fix it in next version.

Posted: Mon Sep 29, 2008 8:26 pm
by patrickbrosset
Thanks a lot for the reactivity.
Looking forward to this new version.

Posted: Wed Oct 01, 2008 10:21 am
by eric_suen
This bug has been fixed in version 1.6.16, thank for report this issue.

Posted: Wed Oct 01, 2008 10:23 am
by patrickbrosset
Thanks a lot.
I'll have a look at version 1.6.16 whenever it is available.

Posted: Wed Oct 01, 2008 10:30 am
by eric_suen
version 1.6.16 is available already.

Posted: Wed Apr 08, 2009 10:51 pm
by cafebabe

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

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

Posted: Tue Jul 17, 2012 11:41 am
by patrickbrosset
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?

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

Posted: Tue Jul 17, 2012 4:13 pm
by eric_suen
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.

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

Posted: Wed Jul 18, 2012 6:32 am
by patrickbrosset
Ok thanks a lot. I'll try that.