AutoComplete and class

Hi, 

I’m trying to make the auto-completion work with my class, but I can’t find a way to make auto completion know that “this class is a child of that class”. 

My first attempt : 

Using the class function from : http://lua-users.org/wiki/SimpleLuaClasses

I get the following. 

“NOTE, I have added a function called new() which does the same thing as metatable.__call, since in another post, you said metatable.__call wasn’t supported : http://forums.coronalabs.com/topic/37493-class-autocompletion-and-custom-sdk/

As you see from the screenshot, function doStuff is not proposed.  

My Second attempt : 

Using the simplistic class system proposed by the book “Programming in Lua” (http://www.lua.org/pil/16.2.html)

If I do a very simple class it works just fine.

But If I do inheritance with a second class, then the autocompletion breaks : 

So,  I was wondering, what is the OOP system suggested for Glider to understand ? 

Thanks !

Simon

Hello Simon,

Please try putting a —@DeepInspect comment on the class() function definition.

---@DeepInspect function class() end

This will prevent Glider from caching the class() return value for performance reasons. Adding the comment should only be necessary for core library functions that are too dynamic to cache the results. 

Please let us know if that helps.

Regards,

M.Y. Developers

Thanks for the reply, 

Unfortunately, same result. I cannot see the funciton Test.doStuff().

I’m kind of confused, since Lua Glider features list Clearly says “Class Aware autocomplete”

http://www.mydevelopersgames.com/Glider/features.html

So what’s the way to do it ? 

Thanks!

Hello Simon,

Since there are no formal “classes” in lua, the class aware autocomplete is slightly open to interpretation, sorry about this confusion. While we make the best attempt to analyze your source code and provide you with the best results, the dynamic nature of Lua makes this difficult. When we say “class aware autocomplete” we mean Gliders ability to track class instances and provide autocomplete suggestions on them. This works best for library functions and simple factory type oop methodologies but we found metatable based oop difficult to analyze properly from a performance standpoint. 

If Glider fails to recognize a class, you can add annotations to help it figure out classes like this:

--the following table just gives Glider an example of what a spaceship object looks like ---@classdef spaceship local SpaceshipPrototype= {} SpaceshipPrototype.speed = 0 --this just tells Glider that speed is a number SpaceshipPrototype.name = "" --this just tells Glider that name is a string SpaceshipPrototype.isAlive = true --this just tells Glider that isAlive is a bool ... ... --Note that you do not need both of the annotations, any one is sufficient. ---@return @class spaceship local function createSpaceship() end ---@class spaceship local spaceshipInstance = createSpaceship()

Hope that helps.

Regards,

M.Y. Developers

Hey again. 

Thanks, that did help. 

What I do now is something like this : 

---@classdef Ammo Ammo = class(Actor) ---@return @class Ammo function Ammo.new(...) return Ammo(...) end function Ammo:init(params)     Actor.init(self, params) self.renderComponent = RenderComponent.new()     --- code... --- end function Ammo:update()      Actor.update(self)     --- more code... --- end  

 So now, I get the init & update function when I call Ammo.new().

I wish there would be a way to see the autocompletion from “myAmmo.renderComponent” though. Right now,  a “not so efficient way” to do that is by adding something like : 

Ammo.renderComponent = nil ---@class RenderComponent

under the “function Ammo.new(…)” line (or anywhere else) so that way, any instances of Ammo knows the class of renderComponent. But it would be great if it could detect it inside the init() function automaticly.  Just on wish-list :). 

Otherwise, the CTRL-Click is all buggy (Go to Declaration). When I CTRL-Click on RenderComponent (or any “class”), it often leads me to a completely random file.  Any explanation for this ? 

Finally, is it possible that I need to open all file before auto completion works ? I have 7 file named Enemy1, Enemy2, Enemy3… , Enemy7,  in my auto-completion I only see Enemy1 and Enemy2 until I open the other files.   Anybody got that issue ? 

Thanks a lot ! 

Hello Lachh,

Sorry about the delay in getting back to you. You may let Glider know about superclasses like this:

---@classdef spaceship @extends ship

So you can use this to explicitly tell Glider about any inherited members.

Otherwise, the CTRL-Click is all buggy (Go to Declaration). When I CTRL-Click on RenderComponent (or any “class”), it often leads me to a completely random file.  Any explanation for this ? 

Where does it end up going? Any patterns in this behaviour?

Finally, is it possible that I need to open all file before auto completion works ? I have 7 file named Enemy1, Enemy2, Enemy3… , Enemy7,  in my auto-completion I only see Enemy1 and Enemy2 until I open the other files.   Anybody got that issue ? 

For performance reasons Glider does not scan all your project files proactively. It only scans them when opened in the editor. To change this behaviour please see this screenshot:

http://view.xscreenshot.com/41ce454ed0fe0a14ebb5d30dcca2c5fa

Please be advised that depending on your project size you may run into performance/memory issues.

Regards,

M.Y. Developers

Hello Simon,

Please try putting a —@DeepInspect comment on the class() function definition.

---@DeepInspect function class() end

This will prevent Glider from caching the class() return value for performance reasons. Adding the comment should only be necessary for core library functions that are too dynamic to cache the results. 

Please let us know if that helps.

Regards,

M.Y. Developers

Thanks for the reply, 

Unfortunately, same result. I cannot see the funciton Test.doStuff().

I’m kind of confused, since Lua Glider features list Clearly says “Class Aware autocomplete”

http://www.mydevelopersgames.com/Glider/features.html

So what’s the way to do it ? 

Thanks!

Hello Simon,

Since there are no formal “classes” in lua, the class aware autocomplete is slightly open to interpretation, sorry about this confusion. While we make the best attempt to analyze your source code and provide you with the best results, the dynamic nature of Lua makes this difficult. When we say “class aware autocomplete” we mean Gliders ability to track class instances and provide autocomplete suggestions on them. This works best for library functions and simple factory type oop methodologies but we found metatable based oop difficult to analyze properly from a performance standpoint. 

If Glider fails to recognize a class, you can add annotations to help it figure out classes like this:

--the following table just gives Glider an example of what a spaceship object looks like ---@classdef spaceship local SpaceshipPrototype= {} SpaceshipPrototype.speed = 0 --this just tells Glider that speed is a number SpaceshipPrototype.name = "" --this just tells Glider that name is a string SpaceshipPrototype.isAlive = true --this just tells Glider that isAlive is a bool ... ... --Note that you do not need both of the annotations, any one is sufficient. ---@return @class spaceship local function createSpaceship() end ---@class spaceship local spaceshipInstance = createSpaceship()

Hope that helps.

Regards,

M.Y. Developers

Hey,

Ok, so for the CTRL_Click being buggy, I found out that it’s when the file isn’t open, so this is related to problem #3 where I have to open file before in order for Glider to scan the project files, as you mentioned. 

I did have the option “Scan Entire Project” checked, anything else to make Glider scan everything ? I had that option checked all along. 

Thanks ! 

Hey again. 

Thanks, that did help. 

What I do now is something like this : 

---@classdef Ammo Ammo = class(Actor) ---@return @class Ammo function Ammo.new(...) return Ammo(...) end function Ammo:init(params)     Actor.init(self, params) self.renderComponent = RenderComponent.new()     --- code... --- end function Ammo:update()      Actor.update(self)     --- more code... --- end  

 So now, I get the init & update function when I call Ammo.new().

I wish there would be a way to see the autocompletion from “myAmmo.renderComponent” though. Right now,  a “not so efficient way” to do that is by adding something like : 

Ammo.renderComponent = nil ---@class RenderComponent

under the “function Ammo.new(…)” line (or anywhere else) so that way, any instances of Ammo knows the class of renderComponent. But it would be great if it could detect it inside the init() function automaticly.  Just on wish-list :). 

Otherwise, the CTRL-Click is all buggy (Go to Declaration). When I CTRL-Click on RenderComponent (or any “class”), it often leads me to a completely random file.  Any explanation for this ? 

Finally, is it possible that I need to open all file before auto completion works ? I have 7 file named Enemy1, Enemy2, Enemy3… , Enemy7,  in my auto-completion I only see Enemy1 and Enemy2 until I open the other files.   Anybody got that issue ? 

Thanks a lot ! 

Hello Lachh,

Sorry about the delay in getting back to you. You may let Glider know about superclasses like this:

---@classdef spaceship @extends ship

So you can use this to explicitly tell Glider about any inherited members.

Otherwise, the CTRL-Click is all buggy (Go to Declaration). When I CTRL-Click on RenderComponent (or any “class”), it often leads me to a completely random file.  Any explanation for this ? 

Where does it end up going? Any patterns in this behaviour?

Finally, is it possible that I need to open all file before auto completion works ? I have 7 file named Enemy1, Enemy2, Enemy3… , Enemy7,  in my auto-completion I only see Enemy1 and Enemy2 until I open the other files.   Anybody got that issue ? 

For performance reasons Glider does not scan all your project files proactively. It only scans them when opened in the editor. To change this behaviour please see this screenshot:

http://view.xscreenshot.com/41ce454ed0fe0a14ebb5d30dcca2c5fa

Please be advised that depending on your project size you may run into performance/memory issues.

Regards,

M.Y. Developers

Hey,

Ok, so for the CTRL_Click being buggy, I found out that it’s when the file isn’t open, so this is related to problem #3 where I have to open file before in order for Glider to scan the project files, as you mentioned. 

I did have the option “Scan Entire Project” checked, anything else to make Glider scan everything ? I had that option checked all along. 

Thanks !