bjornbytes / lovr-docs

Documentation for LÖVR
44 stars 34 forks source link

WIP: Generate LuaCATS annotations #154

Open hmans opened 2 weeks ago

hmans commented 2 weeks ago

Summary

As discussed via Matrix, this PR adds a fresh new LuaCATS API annotations generator to this repository. Please consider this PR work in progress for the time being; I'm opening it at this point in order to discuss further work and gather feedback.

Notes

Testing

To test the generated annotations in a project, point your LuaLS at it like this:

{
  "Lua.workspace.library": [
    "/path/to/lovr-docs/cats"
  ]
}

To run the generator script:

# It's important to do this from the repo root
lua tools/generate-cats.lua

Todo

There's probably more bits and pieces missing. Feedback welcome!

hmans commented 1 week ago

I've identified one slightly annoying caveat (that the existing LuaCATS/lovr repository shares) that can't be fixed without changes to the api/init.lua generation: there's no information about fields on classes/instances. For example, accessing the .x field on a vec3 will always be marked with a warning because the field isn't known (and of course it will be typed unknown.)

I'm guessing that fixing this is, theoretically, a matter of changing the api project to also inject fields information into the objects entries in api/init.lua, but I'm definitely out of my depth here. Is this even possible?

Edit: Implemented (including swizzles.) I've updated the PR description accordingly.