feature: godot docs annotations for LuaLS - #237
Conversation
…om the godot engines xml docs
|
hey there @gilzoide this is my first PR and i apologize if i broke any rules! there were a few things that would be good alongside this like including the .po translation support that godot itself does so people can clone/fork it and build their preferred language, or include plugins to translate it which would require a tiny major refactor you had included a json_types.py for your original structure to go alongside extension_api.json and while it could be helpful i think that with adding the docs it becomes convoluted so i left it out only thing of warning is that tools/code_generation/generate_lua_godot_api.py/parse_godot_class_xml is primarily AI generated (the rest was me offline over weeks) i also noticed that the source of sol2 was the wrong one which was interesting but i included that in this patch alongside some formatting stuff for the other submodules since i was adding a new one (godotengine) and finally i think the next step is adding script_templates! ive already finished that feature as well and will open another PR for this momentarily! this goes without saying but feel free to critique or do whatever you want with this, thank you for the baseline for all of this to be possible |
|
there are some mistakes inside the manual definitions, i unfortunately forgot to review them as i cherry-picked them from one of my personal versions where i was testing making export a metatable with a __call function. will fix this soon |
|
|
gilzoide
left a comment
There was a problem hiding this comment.
Hey @howhow2315, thanks a lot for the contribution! This is a really good idea, making docs in LuaLS much more detailed. Overall, the changes look solid, I have commented some stuff that I found out.
And again, sorry for taking so long to review this, you know how life can be. This PR seemed (and is) quite bigger than the other, that's why I reviewed that one first.
One thing that bothers me is the order of @param and @return in the new docs, almost everywhere I see API docs the brief and long descriptions come first, while this kind of metadata goes last. Why do the opposite?
Another thing, about we using a fork of sol2, it's because the fork fixed a memory leak when indexing metatypes with numbers (see #156). I see in the final diff that it has been changed back, so just keep it like that.
There was a problem hiding this comment.
Why did you pick a "random" commit from tree-sitter instead of a commit tagged as a stable release?
There was a problem hiding this comment.
when i went through and made formatted the submodules i must have messed up!!! half of them had a mismatched naming convention, some being lib/*, and some just being *
my fault !!
| BRANCH = "master" | ||
| # BRANCH = "4.6" |
There was a problem hiding this comment.
This is never used and likely doesn't need to exist here.
There was a problem hiding this comment.
yeah i agree completely just something i had in mind while i started writing
There was a problem hiding this comment.
I see this script generates definitions for classes/@GDScript.lua. These are GDScript only and are not available in Lua, we should filter them out. Lua defines most of them via the utility functions, while some are built-in (such as await).
There was a problem hiding this comment.
youre completely correct, since that file is extremely long just like @GlobalScope i was using it to test things, i should have removed it
| None: "nil", | ||
| "inf": "math.huge()", | ||
| "[]": "{}", # the value ends up as just "[]", this would be an ordered table yes? we should probably just use a table | ||
| "nan": "0/0", # adding a math.NAN would probably be a good idea |
There was a problem hiding this comment.
adding a math.NAN would probably be a good idea
In Lua? Lua doesn't define NaN and lets one generate one easily (such as with 0/0), I don't think we need to bother.
| [ | ||
| "tools/code_generation/generate_lua_godot_api.py", | ||
| "lib/godot-cpp/gdextension/extension_api.json", | ||
| ], |
There was a problem hiding this comment.
Now that this script also reads lib/godot/... we might want to add at least one dependency here to rebuild the docs in case the commit for lib/godot changes. Also add doc_classes from Lua GDExtension, since it is also used by the script.
|
|
||
| return text | ||
|
|
||
| def parse_godot_class_xml(xml) -> Dict[str, Any]: |
There was a problem hiding this comment.
I'm getting a NameError: name 'Dict' is not defined. Did you mean: 'dict'? error here. Python 3.13.9 on a macOS, installed from pyenv.
You should either use dict or import Dict from typing.
There was a problem hiding this comment.
i think i removed my Dict import by accident in my last cleanup and i didnt catch it because of my venv
| "addons/lua-gdextension/lua_api_definitions/variants", | ||
| "addons/lua-gdextension/lua_api_definitions/enums", | ||
| "addons/lua-gdextension/lua_api_definitions/functions", | ||
| "addons/lua-gdextension/lua_api_definitions/classes" |
There was a problem hiding this comment.
Now that the generated files changed, you should add these new folders to .gitignore.
There was a problem hiding this comment.
i swore i did a catch all with "addons/lua-gdextension/lua_api_definitions/*" and "!addons/lua-gdextension/lua_api_definitions/manual",
| # i believe the docs include something like "**Deprecated: This is the reason why and or what to use instead" | ||
|
|
||
| # i assume we should express methods with `:` instead of `.` | ||
| # im pretty sure lua-gdextension forces use of : no matter what, but how does it work with static methods? |
There was a problem hiding this comment.
Static methods are also forced to use :. Maybe they shouldn't, we can discuss that, but right now they are.
There was a problem hiding this comment.
- In the Variants side, this script generates definitions for Nil, which doesn't exist in Lua
- Constructors for Variants use the call syntax instead of
:new:Vector2(1, 2)
There was a problem hiding this comment.
yeah im 100% sure i thought about both of those things and went "ill just add it in case" 😭
| # as well as for the value and type instead of manually in each spot its required | ||
|
|
||
| # TODO | ||
| # deprecated |
There was a problem hiding this comment.
There could be a [deprecated] tag in the same place as [static] and [const].
Goal
Improve Lua language support for Godot by integrating official engine XML documentation and upgrading annotation definitions used by LuaLS, making engine APIs faster, and easier to work with in the editor.
Changes
Added Godot engine submodule containing XML documentation for annotations
Updated LuaLS annotation definitions to include Godot XML docs annotations
Separated manual definitions into their own files in a subdirectory for clarity and maintainability
Switched sol2 dependency to the official upstream repository
Grouped submodules in .gitmodules by subsystem for better structure
Renamed and reorganized submodules to match repository path naming conventions
Performed small diagnostics cleanup and general organization improvements