Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Koneki » Autocompletion for external API
Autocompletion for external API [message #1417005] Sun, 03 November 2013 07:28 Go to next message
anto gerva is currently offline anto gervaFriend
Messages: 19
Registered: June 2012
Location: Canada, Québec
Junior Member
Hi there,

Let's say I want to add documentation to an external dynamic library such as http://keplerproject.github.io/luafilesystem/, in order to get a autocomplete feature over http://keplerproject.github.io/luafilesystem/manual.html#reference. Right now, I'm pretty sure it's impossible to link a source package like it can be done in java, since usually these external library that aren't .lua are wrote in C.

So, if the programmer really want to get autocompletion for this, he can either try to:
-Create a class with documentation that somehow "mock/mimic" the external library(but when running the program, he switch to the real library).
-Create somekind of an adapter class with documentation where he simply recall the original library for each field and function.

So far, I guess that Koneki has probably some other priorities, but I was wondering if there could be something to be done here.

I mean, once we use the "require" statement for an external library, it's possible to detect a new table/module on _G. Then, it's usually possible to detect wether the "top element" inside the said component is a function/variable/userdata with his related name. Here's a piece of code that show what I mean(borrow from http://lua-users.org/wiki/TableSerialization : "Universal tostring"):

function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
if type(tt) == "table" then
local sb = {}
for key, value in pairs (tt) do
table.insert(sb, string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done [value] then
done [value] = true
table.insert(sb, "{\n");
table.insert(sb, table_print (value, indent + 2, done))
table.insert(sb, string.rep (" ", indent)) -- indent it
table.insert(sb, "}\n");
elseif "number" == type(key) then
table.insert(sb, string.format("\"%s\"\n", tostring(value)))
else
table.insert(sb, string.format(
"%s = \"%s\"\n", tostring (key), tostring(value)))
end
end
return table.concat(sb)
else
return tt .. "\n"
end
end

function to_string( tbl )
if "nil" == type( tbl ) then
return tostring(nil)
elseif "table" == type( tbl ) then
return table_print(tbl)
elseif "string" == type( tbl ) then
return tbl
else
return tostring(tbl)
end
end

So my question, would it be possible to add autocomplete for a dynamic library(.dll on windows or .so on unix)?

Thanks again,
Btw, I've compilled 1.1_M2 with maven3 for testing this http://www.eclipse.org/forums/index.php/t/528888/ and it seem to work great now, as long as we respect the luadoc nomenclature :)
Re: Autocompletion for external API [message #1417006 is a reply to message #1417005] Wed, 06 November 2013 17:42 Go to previous messageGo to next message
Simon Bernard is currently offline Simon BernardFriend
Messages: 337
Registered: July 2009
Senior Member
Hi,
Thanks for feedback :)

A solution for your problem, could be to create a mock file with the API written with the documentation language, to package it in a zip file and to add it to the sourcepath/buildpath
(right on your project/ Build Path / add External Archives)
In this case, the file will be not used at runtime and you don't need to implement adapter or to switch manualy.

HTH :)
Re: Autocompletion for external API [message #1417008 is a reply to message #1417005] Wed, 13 November 2013 11:16 Go to previous messageGo to next message
anto gerva is currently offline anto gervaFriend
Messages: 19
Registered: June 2012
Location: Canada, Québec
Junior Member
Thanks, writing the mock API is a bit more work but it's actually worth it!

Also, since there's already an api.zip for storing the global lua function/value, which come with koneki* it look like that this is the best way add documentation. Also, I just saw that there's already seem to be some plan for adding additionnal "http://wiki.eclipse.org/Koneki/LDT/Technical_Documentation/Documentation_Language#Inference" tools later, so it's all great :d

*In the "configuration\org.eclipse.osgi\bundles\177\1\.cp\resource\lua-5.1" folder
Re: Autocompletion for external API [message #1417014 is a reply to message #1417006] Fri, 22 November 2013 15:56 Go to previous messageGo to next message
anto gerva is currently offline anto gervaFriend
Messages: 19
Registered: June 2012
Location: Canada, Québec
Junior Member
Simon Bernard wrote on Wed, 06 November 2013 12:42
> A solution for your problem, could be to create a mock file with the API written with the documentation language, to package it in a zip file and to add it to the sourcepath/buildpath
> (right on your project/ Build Path / add External Archives)
> In this case, the file will be not used at runtime and you don't need to implement adapter or to switch manualy.


In Koneki 1.1_M2, I could go in build path > source > Add Folder and this new folder path could be used as source for the autocompletion when using require statement. No need to zip those(which is very useful, so I can add these external API on the go, without zipping/unzipping for every change). Also, at the time, the buildpath wasn't added in package.path variable.

Now I recently made a check out of the "master" branch and all these path are added in package.path variable when I execute a lua script and there no way to exclude them of this variable or to uncheck them in "Order and Export" :x

Furthermore, in "Libaries" > "Add Library..." > "Lua User Libraries", I get the following exception:
Plug-in org.eclipse.koneki.ldt.ui was unable to load class org.eclipse.dltk.internal.ui.internal.wizards.buildpath.UserLibraryWizardPage.
org.eclipse.dltk.internal.ui.internal.wizards.buildpath.UserLibraryWizardPage cannot be found by org.eclipse.koneki.ldt.ui_1.1.0.201311012011

Since this wasn't a official release, I know these kind of error can be expected, so I just wanted to let you know about this :)
Re: Autocompletion for external API [message #1417016 is a reply to message #1417014] Tue, 26 November 2013 11:04 Go to previous messageGo to next message
Simon Bernard is currently offline Simon BernardFriend
Messages: 337
Registered: July 2009
Senior Member
In koneki 1.1M2, there are a regression with lua path and cpath settings. We fix this one recently. So the feature you used was a bug :d.

Currently, the only way to add library at IDE side which are not added in path at runtime is the zip archive (or the execution environment but this should not be used for that :p).

I will open an enhancement for this use case. This will not be implemented for the 1.1 :)
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=422555)

For the second problem about User library, You found another bug :). I just fix it in master (commit 75fd356cf4892462f16fa5a9239007df57beb0c3)
Re: Autocompletion for external API [message #1417019 is a reply to message #1417016] Wed, 27 November 2013 17:55 Go to previous messageGo to next message
anto gerva is currently offline anto gervaFriend
Messages: 19
Registered: June 2012
Location: Canada, Québec
Junior Member
Thanks! This enhancement would be a nice little addition :d

Other than that, this is a bit off-topic, but I was wondering why does Koneki use luasocket for debugging, rather than let's say http://www.zeromq.org/. I known that luasocket isn't a developped a lot recently and you have to some work around to get it work with lua 5.1 and 5.2. But I figured that there might be some reasons like the fact that http://keplerproject.github.io/lua-xmlrpc/manual.html#introduction use luasocket?

Anyway, I was just wondering!
Thanks!
Re: Autocompletion for external API [message #1417021 is a reply to message #1417019] Thu, 28 November 2013 11:43 Go to previous messageGo to next message
Simon Bernard is currently offline Simon BernardFriend
Messages: 337
Registered: July 2009
Senior Member
In fact, its possible to use any transport layer for debugging. But you need to implement a specific layer abstraction.

To implement your own transport interface based on your own library (see the http://git.eclipse.org/c/koneki/org.eclipse.koneki.ldt.git/tree/libraries/luadbgpclient/debugger/transport/fake.luaand the http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_1.0#transport_parameter)
(We probably need more documentation on that :/)

We currently provide by default the luasocket implementation because we think that luasocket is the most popular library for socket in lua.

You could try to make an implementation for ZMQ. We could make a wiki page to reference all the transport layer implementation for LDT as we do for execution environment.(and so reference your ZMQ implementation and maybe one day we could integrate it directly in LDT)
Re: Autocompletion for external API [message #1500622 is a reply to message #1417006] Sat, 06 December 2014 04:07 Go to previous message
Marc Bradley is currently offline Marc BradleyFriend
Messages: 5
Registered: December 2014
Junior Member
Simon Bernard wrote on Wed, 06 November 2013 17:42
Hi,
Thanks for feedback Smile

A solution for your problem, could be to create a mock file with the API written with the documentation language, to package it in a zip file and to add it to the sourcepath/buildpath
(right on your project/ Build Path / add External Archives)
In this case, the file will be not used at runtime and you don't need to implement adapter or to switch manualy.

HTH Smile


So here is a simple "mock file" I made to test this.

-------------------------------------------------------------------------------
-- test 123.
-- @module my



-------------------------------------------------------------------------------
-- Returns the absolute value of `x`.
-- @function [parent=#my] abs
-- @param #number x
-- @return #number

return nil


This is a chunk of math.doclua that i renamed to my.doclua
I zipp this file, I right clic on my project, choose buildpath/add external archives then choose my.zip. I then see all the doc in the Luadoc window in Eclipse but it doesn't enable autocompletion in the editor window. If I start writing "my.", like I would do with "io." or "math." Eclipse LDT doesn't autocomplete like it would do with the Lua Execution Environement libraries. Am I missing something ?




Previous Topic:Lua Modules
Next Topic:Compiling for Lua C API to call LibSndFile functions
Goto Forum:
  


Current Time: Tue Sep 25 03:34:27 GMT 2018

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

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

Back to the top