Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Lua Development Tools » Autocompletion for external API
Autocompletion for external API [message #1168304] Sun, 03 November 2013 07:28 Go to next message
anto gerva is currently offline anto gerva
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 LFS, in order to get a autocomplete feature over these function. 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(borrowed from 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


Then we can do something like
require "lfs"
print(to_string(lfs))

While this isn't the best implementation, the only downside is that we don't know the suggested parameter for a function.

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 issue and it seem to work great now, as long as we respect the luadoc nomenclature Smile

[Updated on: Sun, 03 November 2013 20:48]

Report message to a moderator

Re: Autocompletion for external API [message #1173686 is a reply to message #1168304] Wed, 06 November 2013 17:42 Go to previous messageGo to next message
Simon Bernard is currently offline Simon Bernard
Messages: 282
Registered: July 2009
Senior Member
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
Re: Autocompletion for external API [message #1184321 is a reply to message #1168304] Wed, 13 November 2013 11:16 Go to previous messageGo to next message
anto gerva is currently offline anto gerva
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 "Inference" tools later, so it's all great Very Happy

*In the "configuration\org.eclipse.osgi\bundles\177\1\.cp\resource\lua-5.1" folder
Re: Autocompletion for external API [message #1203336 is a reply to message #1173686] Fri, 22 November 2013 15:56 Go to previous messageGo to next message
anto gerva is currently offline anto gerva
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 Koneki of the "master" branch(last commit is 4854af99e64e3ddd1c77920a482f89e660fcb198 ) and all theses path from the buildpath are added in package.path variable when I execute a lua script. I didn't find a way to exclude those path theses "folder variable" or to uncheck them in "Order and Export". Before, I thought we had to go in Preferences > Lua Interpreters > Edit in order to add customize path. That's why I got a bit confuse Surprised

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


That said, I can still work around these issue without problem, so nothing be stressed about either, I just wanted to let you know about this Smile

Also, I tested if reference works between modules and now it work pretty good!

[Updated on: Fri, 22 November 2013 17:35]

Report message to a moderator

Re: Autocompletion for external API [message #1211284 is a reply to message #1203336] Tue, 26 November 2013 11:04 Go to previous messageGo to next message
Simon Bernard is currently offline Simon Bernard
Messages: 282
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 Very Happy.

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 Razz).

I will open an enhancement for this use case. This will not be implemented for the 1.1 Smile
(Bug 422555)

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

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 ZMQ? I known that luasocket isn't a developped a lot recently and you have to do some workaround in order to get lua 5.1 and 5.2 working. But I figured that there might be some good reasons like the fact that Lua XML-RPC use luasocket? So if the other lua tool for socket stay with luasocket it's better to stick with it?

Anyway, I was just wondering! Maybe I should just check more the source of Koneki to find out why.

[Updated on: Wed, 27 November 2013 18:01]

Report message to a moderator

Re: Autocompletion for external API [message #1216255 is a reply to message #1214437] Thu, 28 November 2013 11:43 Go to previous message
Simon Bernard is currently offline Simon Bernard
Messages: 282
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 interface and the 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)
Previous Topic:Editing Syntax Coloring
Next Topic:Sample code used in LDT to generate AST
Goto Forum:
  


Current Time: Mon Sep 15 09:32:22 GMT 2014

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

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