ZeroBraneStudio
ZeroBraneStudio copied to clipboard
Tables / Records / Classes / Structs and autocompletion
I have a record/class/struct or I think in Lua terms they are called tables, e.g. like a Player or Person residing in it's own file (person.lua or player.lua) which is then required in main for example:
player = {}
and later on I go ahead an add properties like
player.x = 50
player.y = 50
player.xvel = 0
player.yvel = 0
player.width = 50
player.height = 50
player.friction = 7
player.speed = 2250
etc....
These properties cannot be autocompleted for some reason when I use them. Also I tried to have the properties default initiated in it's file like:
player = {
x = 0,
y = 0,
xvel = 0,
yvel = 0,
width = 0,
height = 0,
friction = 0,
speed = 0
}
I hope this hasn't be asked or solved before. Also I am pretty new to Lua and I am using this in conjunction with Love2D. Thanks!
@paines, this is not currently supported and would be an interesting feature to add. Are these descriptions in the same or a different file? There is already a similar ticket (#126), although it is for tables described in "required" files.
The descriptions would reside in the same file. In other files, like main.lua I would use those in a reading kind of way like
if player.x < screen.width then
doSomethingFunky()
end
Please contact me if I can support you with testing.Thanks!
Another related ticket is #485. I'll definitely take you up on your testing offer when there is something to test ;).
@pkulchenko You can count me in for both wishing this feature and testing it :)
Although having this feature in files require
d would be great, first getting this to work on a single file would be great. E.g. main.lua
:
--- One line summary of the function.
-- Some description, can be over several lines.
-- @param p1 first parameter
-- @param p2 second parameter
-- @return a boolean value
function captureTheFlag(p1,p2)
--
end
capt|
should show the above function as a completion candidate, also if the function has a LDoc kind of comment above it, showing it as tool tip would be good.
should show the above function as a completion candidate
@legends2k, it should do this already; captureTheFlag
should be offered in auto-complete and it takes into account global and local variables (so it will only offer those that are available at that particular location).
The IDE doesn't do much with LDoc comments at the moment, although it uses them in the functions to get the types to some degree, so if you do -- @tparam string p1 first parameter
(instead of @param
), then the IDE will "know" that p1
is a string and will offer string methods after p1:
(when used in the function).
@legends2k, I should mention that the functionality I described above is available probably in 1.20+, so if you are using an older version, you may want to upgrade.
I'll definitely call for review/testing when this is implemented, so thanks for the offer.
@pkulchenko I've zbstudio 1.30 and yes, when I type capt
, it does show the function as completion candidate. I think I wanted showing of call tip for a user-written function while I wrote about auto completion, my bad :(
Say I type pri
and select print
(the standard library function) from the list of candidates, and then type (
, it shows print
s call tip, about the number and type of parameters it takes, along with detailed documentation. Doing this for custom functions would be good; although displaying the detailed documentation isn't always possible, just showing the parameter names would be a great start e.g.
captureTheFlag(
+----------+
| p1, p2 |
+----------+
This gives a pretty good idea, when writing the calling code, of the number of arguments and, with descriptive names at the defining code, about their types too.
Showing the parameter types and detailed documentation might not be easy since there's no standard way to document in Lua; LDoc is just one convention, there might be others. So to avoid this issue, some IDEs like Visual Studio, show the entire set of comment lines that precede a function definition, after stripping comment characters like /*
, */
and //
i.e. in our case would be --
, --[[
, ]]
and long comments of higher levels.
I agree; showing the tooltip with that information would be nice; currently it's only used for type assignment heuristics.
The tricky parts is updates; right now the API shown is static (it doesn't change after the IDE is launched, even though different plugins can add/remove their own API descriptions). If it's dynamic and can change as you update the code, the mechanism that handles tooltips and related functions needs to support that.
Agreed, every time some function is "visited" (edited), it should be revisited by the parser and indexed again. It needs multi-threading, and with it comes its own problems like synchronizing between reads and writes to the index.
Any update regarding this topic? Would love to see autocompletion for tables.
@KevinW1998, there hasn't been recent changes to this functionality. Autocompletion for tables require deeper (and slower) analysis than what's currently available (although there is probably enough information after parsing to enable that).
One of the recent changes somewhat related to this was adding indexing of symbols in all files in your current project (available as Search | Navigate | Go To Symbol
), but this information is not currently used in auto-complete.
Not sure if this would be simpler but notepad++ has a neat feature where it simply adds any word in the file to the autocomplete list. It doesn't understand the relationships between the words so if you had... local atable={firstmember=1,secondmember=2}; atable. the autocomplete would not know firstmember/secondmember were valid. However if you type atable.fi its smart enough to suggest firstmember, which helps with typos quite a bit.
@csterling4, good point. ZeroBrane Studio has that as well, you'd need to set acandtip.nodynwords=false
in the config. See https://studio.zerobrane.com/doc-general-preferences#auto-complete-and-tooltip for details.
thank's for this tips ! now with littles packages, my Zerobrane is perfect !