Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Lua Development Tools » Help understanding code assist(I need help understand what can an cannot autocomplete)
Help understanding code assist [message #1012000] Wed, 20 February 2013 17:00 Go to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
I'm relatively new to Lua, and very new to Koneki. I've setup the LDT tool and been able to get a project setup and working with most functionality. I'm confused though on exactly what I can auto-complete and ctrl-click. If everything is local it seems that things are working okay, but I'm trying to figure out what I can do with modules.

To be specific -

If I have
-- simpleModuleA.lua
module(..., package.seeall)

function myFunc()
  print('hello')
end


-- useModule.lua
local myModA = require('simpleModuleA')

-- insert question code here.


If at the point noted in the code I start typing "myMo" and then hit ctrl-space it will auto complete the local variable "myModA". However, if then have "myModA." and hit ctrl-space I do not get any suggestions for available functions. Is this normal?

Also if I have in the code "myModA.myFunc()" I cannot ctrl-click on "myFunc" and go to the definition of myFunc. However, if I ctrl-click on "MyModA" and get taken to the declaration of myModA.

Is this the expected behavior or do I have something set up wrong. I would really like the ability to ctrl-click into my modules or have auto-complete for functions.

Also, when I am writing simpleModuleA I have to have everything 'global' in that file (i.e. "function myFunc" instead of "local function myFunc") in order to have it visible when I try to do myModA.myFunc. If that is the case I can't have any auto completion on that function when writing that file because it is a global?

Thanks for helping me understand this.
Re: Help understanding code assist [message #1012414 is a reply to message #1012000] Thu, 21 February 2013 14:24 Go to previous messageGo to next message
Kevin KIN-FOO is currently offline Kevin KIN-FOOFriend
Messages: 50
Registered: January 2010
Member
Hi Kevin,

About modules, the module function won't work with Lua 5.2. So, you might start to create modules from tables. Then, in this case, you will not handle any globals.
local M = {}

M.myFunc = function()
  print('hello')
end

return M

As I'm writing, we analyze modules from their documentation comments[1]. Your module was not documented, that is why you did not have content assist available on it. Once documented, Ctrl-clicking your module's attributes will lead you to their documentation.

To unleash Koneki LDT you might read its Getting Started[2] from its User Guide[3], thanks for your feedback.

Kévin

[1] Lua Documentation Language: http://wiki.eclipse.org/Koneki/LDT/User_Area/Documentation_Language
[2] Getting Started: http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9#Getting_started
[3] User Guide: http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9
Re: Help understanding code assist [message #1012462 is a reply to message #1012414] Thu, 21 February 2013 15:51 Go to previous messageGo to next message
Simon Bernard is currently offline Simon BernardFriend
Messages: 288
Registered: July 2009
Senior Member
Hi,
If you want more information to understand why we support module autocompletion only from documentation for now, you could read :

http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Assistance
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370583
http://www.eclipse.org/forums/index.php/mv/msg/351391/871701/#msg_871701
https://bugs.eclipse.org/bugs/show_bug.cgi?id=381671
Re: Help understanding code assist [message #1012488 is a reply to message #1012414] Thu, 21 February 2013 16:50 Go to previous messageGo to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Thank you for your response. I had already read through the guides you mentioned, though I may have missed a few things. Also, my actual code is documented according that which is described in the documentation guide (at least I think it conforms - it works correctly with the html document generator). I realized after I posted that I should have put that in my example.

The reason I am using the 'module' function is a bit complex though. I am working with another piece of software which parses lua files and is looking for very specific naming conventions. The code requires the prefix 'cmp' on the table name and does not allow '.' as a valid character in the name. Such that cmpMyThing is valid but M.cmpMyThing is not valid, nor would be cmp.MyThing. This is less than ideal, but is what I have to deal with in the short term. Long term I may be able to change the parsing algorithm. To get around this right now I am using the module function, which allows me to just put cmpMyThing into the file as a global. This makes the parser happy. I am using the 'squish' utility to merge files together into a single file (also required for this software). This utility leaves the cmpMyThing intact so that it can still be parsed properly.

Anyway, your post leads me to believe I need to do two things
1. Create a more simple example than my current code to try out if code assist is working properly
2. Examine other possibilities of how to work around the limitations of my software if I want to use all the features of LDT. I would rather use the method you described for creating modules, but I need to figure out another way to make it work with the parsing constraints I have.

I'll post again if my experimenting with code assist fails.

Kevin
Re: Help understanding code assist [message #1013136 is a reply to message #1012488] Fri, 22 February 2013 21:34 Go to previous messageGo to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Thanks again for help on this. I solved the problem. I was able to find a way to get around using the module function so that I could define my modules with the local M = {} method. My real problem though, was that I was declaring tables inside my module as types and not fields. I had misunderstood the documentation description, thus nothing was showing up on ctrl-space because they were declared as types and not fields with the right parent.
Re: Help understanding code assist [message #1013149 is a reply to message #1013136] Fri, 22 February 2013 22:24 Go to previous messageGo to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Ok, sorry, I'm still confused on one point. If I make my tables fields I can see them outside the module with code assist. But I don't understand how to see something inside that table. Can I only go one level deep?

As example again -
---
-- Simple Module for testing documentation.
-- Just for test.
--
-- @module docTest
local M = {}

---
-- A Table.
-- What should this be??? A field, a Type?
-- 
-- @field [parent=#docTest] #table myTable
M.myTable = {}

	--- 
	-- Function in a table.
	-- What should the parent be???
	-- 
	-- @function [parent=#myTable] myFunc
	function M.myTable.myFunc()
		-- Do something
	end

return M


If I do this outside the module
local test = require 'docTest'
test.myTable.--try auto complete here


I can't auto complete to get the function myFunc. Is this possible, and if so what do I need to do to make the documentation work correctly? I'm confused at exactly when you use the '@type' in the documentation. Originally I thought that I should use that on my tables so I could then use the @field for the table fields. But that doesn't work either because then I can't see my table outside the module.

Thanks for any help.

Kevin
Re: Help understanding code assist [message #1014773 is a reply to message #1013149] Tue, 26 February 2013 12:48 Go to previous messageGo to next message
Marc Aubry is currently offline Marc AubryFriend
Messages: 83
Registered: August 2012
Member
Hi Kevin,

You're right, the @type is the clue.
The @type allow to define a kind of set/container of functions and fields. You can also associate a type to a variable such as a function return or a field.
If a variable have a defined type, the auto-completion will known all the functions and fields available on it.

To fix your code, you just need to declare the new type "mytable" using @type,
set the field type to #mytable instead of #table, and set the parent of MyFunc to "#mytable".

---
-- Simple Module for testing documentation.
-- Just for test.
--
-- @module docTest
local M = {}

--- @type mytable

---
-- A Table.
-- What should this be??? A field, a Type?
-- 
-- @field [parent=#docTest] #mytable myTable
M.myTable = {}

	--- 
	-- Function in a table.
	-- What should the parent be???
	-- 
	-- @function [parent=#mytable] myFunc
	function M.myTable.myFunc()
		-- Do something
	end

return M


Now, when you require the module "testdoc" in an other file. The test variable will be associated to the type "docTest", so you can call the field "mytable". And as the field myTable is associated with the type "mytable" the function "myfunc" is available for the auto completion.

I hope theses explanations can help you.

Feel free to post here if you have any feedback on this mechanic or the documentation, it's helpful for us to understand Lua developer point of view.

Marc
Re: Help understanding code assist [message #1015155 is a reply to message #1014773] Wed, 27 February 2013 15:35 Go to previous messageGo to next message
Simon Bernard is currently offline Simon BernardFriend
Messages: 288
Registered: July 2009
Senior Member
Currently there is a bug which prevents to declare the @type after you reference it. You can follow it here.
Re: Help understanding code assist [message #1015181 is a reply to message #1015155] Wed, 27 February 2013 16:50 Go to previous messageGo to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Thank you for your help on this. As for feedback - I think it would be helpful to have an example of this in the documentation. I read through it several times and could still not figure out exactly how to use the @type keyword. I think showing an example with creating a type and then using it would be very helpful. I did not realize that I would need to say '#myTable myTable'. I would have thought that it could have inferred that by simply giving the name 'myTable'. I missed the fact that it is both a field AND a type, and that I have to explicitly declare both.

As I read back through the documentation I think that things that were difficult for me is the language for a field 'It is always a field of a type'. That makes me feel like they are mutually exclusive things. I was thinking of my table as the parent to the fields inside the table - and thus it must be a type. But if it is a type it is not a field. As I now understand it, though, the type is just an arbitrary tag to which to attach things and is not actually tied to the table itself (that is I can call my type 'bob' and declare a field as #bob myTable). In any case I think a simple example showing that would make all troubles understanding go away. As it stands the one 'Sample mixing code and comments' does not declare a new type and use it. Just adding a few lines of code to that example, I think, would make it much more clear how to use it.

One other comment on the documentation system - I noticed that since the autocomplete is based solely on the documentation it is possible to autocomplete something that is not legal. If I mistype the name of my field when creating the documentation (i.e. myTalbe) then when I ctrl-space it will suggest the incorrect value name. I'm sure you're already aware of that limitation but I thought I would mention that I noticed it as a potential problem.

Thanks again. I really appreciate your responsiveness in this forum. That is the primary reason I decided to go with LDT over other options - it seemed to be the tool with most active development and community participation.
Re: Help understanding code assist [message #1015614 is a reply to message #1015181] Fri, 01 March 2013 11:38 Go to previous messageGo to next message
Simon Bernard is currently offline Simon BernardFriend
Messages: 288
Registered: July 2009
Senior Member
You're right, we should probably provide a sample of complete Lua module which defines its own type in this documentation : http://wiki.eclipse.org/Koneki/LDT/User_Area/Documentation_Language.
(The io module in lua 5.1 execution environment is a good one but we should probably include a sample with lua code)

The documentation language aims to describe the API, and not really the implementation (the code you write).
There are no way in lua to define a type and name it, so we add this notion but there are no direct link between the type declaration and its implementation.

In your sample the developer which use your module should know :
- you define a module (docTest). (when you define a module you implicitly define a type with the same name)
- This docTest type has one field named 'mytable' which is typed. (it could be of type : string, a number, or complex type defined with @type or just not typed)
- In your case you use a complex type to type your field. The type is named "mytable" (not really a good name, should be better to call that "mytype").
This Type has one field which is a function.

Perhaps if we write the code like that it's more clear ?
---
-- Simple Module for testing documentation.
-- Just for test.
--
-- @module docTest
local M = {}


---
-- My type
-- @type mytype
-- @field #string f1 my field
local T = {f1 = "val1"}
--- 
-- field of mytype which is a function.
-- @function [parent=#mytype] myFunc
function T.myFunc()
	-- Do something
end


---
-- A field of type mytype.
-- 
-- @field [parent=#docTest] #mytype myTable
M.myTable = T 
---
-- A field of type string
-- @field [parent=#docTest] #string anotherfield
M.mystring = "val2"

return M


But I agree the notion of type is more clear when you want to describe Oriented Object API than a simple nested tables API.

Perhaps we should search a simple syntax for nested tables.
Re: Help understanding code assist [message #1016089 is a reply to message #1015614] Mon, 04 March 2013 22:27 Go to previous messageGo to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
I think your code example makes the ideas more clear. It makes more sense to see explicitly defining a type and then setting something else to be of that type. I may not always think of coding this way though, if I'm only making one of the type. There's not really a point in declaring a type (T) only to give it a different name (myTable) a few lines later. If I'm going to make more than one (i.e. I also have mySecondTable = T) then I would definitely think about coding it as you have described. But in any case I think that example clearly illustrates how to use the documentation to define a type and shows why it is the way it is.

One other question for you - While I'm working inside the module do I have any way to use the autocomplete? For instance, if in your example, right before the line 'return M' if I type 'M.' and try to ctrl-space I don't get any information about fields in my module (docTest). If I want to get myTable, or even myTable.myFunc while I'm still writing inside the module can I do that?
Re: Help understanding code assist [message #1016661 is a reply to message #1016089] Thu, 07 March 2013 09:47 Go to previous message
Simon Bernard is currently offline Simon BernardFriend
Messages: 288
Registered: July 2009
Senior Member
Thx for your feedback.

In LDT v0.9, the autocompletion based on documentation language is only proposed for external use.

If you document your module, when you use it in another file you will have autocompletion but not in the documented module itself.

Our priority will be to provide a way to discover/use easily new API. I mean propose assistance in priority for client of an API, but I agree this is clearly a limitation and we currently working on it, we hope this will be include in the v1.0.

You could have a look of the plan : http://wiki.eclipse.org/Koneki/LDT/Developer_Area/Project_Plan/1.0

Previous Topic:LUA development tools not running in order
Next Topic:Lua and C++ exception: will my scripts be still debuggable?
Goto Forum:
  


Current Time: Sun Nov 23 14:49:14 GMT 2014

Powered by FUDForum. Page generated in 0.02891 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software