Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate Lua API documentation #1998

Merged
merged 21 commits into from
Feb 13, 2024
Merged

Conversation

alerque
Copy link
Member

@alerque alerque commented Feb 8, 2024

Closes #1337

Still need to think of a place to host this.

@alerque
Copy link
Member Author

alerque commented Feb 10, 2024

For now I assume a single version rebuilt from a branch HEAD will be fine. At the moment the docs are pretty spotty. Whet it gets to the point of being generally useful we would probably want to host versions matching SILE releases. The same will be true of manuals and Rust API docs.

This probably means getting the Nix Flake setup with an option to generate docs, then using that from the website repo build script to generate the docs for desired branches and tags as part of the static site build.

@alerque alerque added the documentation Documentation bug or improvement issue label Feb 10, 2024
@alerque
Copy link
Member Author

alerque commented Feb 12, 2024

The issue of versioning (and hence stable URS) is not addressed yet, but the Lua API docs are being posted on the SILE website: https://sile-typesetter.org/lua-api/.

Definitely not complete but, enough that even I've learned some about SILE internals from reading them!

I'm probably going to merge this soon because this needs to be added to and tweaked as the main develop branch, not off here on its own.

@alerque alerque marked this pull request as ready for review February 12, 2024 20:49
@alerque alerque requested a review from a team as a code owner February 12, 2024 20:49
@alerque
Copy link
Member Author

alerque commented Feb 12, 2024

(Rebuilds currently happen running the website repo CI, not the CI for this repo. I'm looking into how to setup a rebuild hook so the website updates any time the development branch does.)

---@return table|nil AST command node
-- looking only at the first level.
-- (We're not reimplementing XPath here.)
-- @tparam table tree AST tree
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Omikhleia I think I recall you saying the type hinds you added here worked in VSCode. I can't find the discussion but I have a memory of saying we probably wanted to use LDoc format in the future but that something was better than nothing to start with. This PR adds LDoc support and hence I tweaked these with type hints for that system. That being said it would be nice to figure out what else these can be used for and if we can figure out a way they work for everybody. Were you using these for an LSP or something? If so which one? And does this format work too? Or do we need to figure out how to adapt the type hints in a way that work for multiple systems?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LDoc has quite a few ways of handing tags. Before I get too fancy with them I want to know if they are going to be used for anything other that ldoc.

For example @tparam string var defines a parameter of type string named var, but it also has \string var as an alias for the same thing. We can also setup custom types, which I want to do so we can have @tparam measurement width or @tparam ast tree for example that are linked to SILE.types.measurement and SILE.types.ast (or whatever that ends up going, right now it's just a table).

Copy link
Member

@Omikhleia Omikhleia Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alerque There are a bunch of LSP and VSCode add-ons for Lua. I currently use https://github.com/Tencent/LuaHelper -- I can't remember why I picked that one... I also tried https://luals.github.io/ at one point (installed on my main host, but disabled).

Both have helpers to generate the documentation from code, and a fairly similar syntax for parameters, with @param name type description -- in line with my plugins for other languages (Typescript, Python...), mimicking their conventions for optional parameters and variant types (e.g. table? and/or table|nil etc.)

I am afraid LDoc's @tparam is quite specific to it, and doesn't have much support elsewhere... Likewise, marking optional params with[opt] seems unusual (AFAIK)
It's annoying people keep reinventing the wheel there, with their own language documentation things.
I am not going to type those manually if I can avoid :) Hopefully, Copilot can help here too, though I don't always have it on (esp. in vacations, with a low/limited bandwidth).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition: It seems both plugins I mentioned use EmmyLua annotations (or a variant?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 🤦 🤦

EmmyLua looks like a disaster to me, but the luals (formerly Sumneko Lua) stuff looks promising. They are not the same but both allow some customization and it might be possible to map out a dual-purpose ground that has some meaning to both.

lunarmodules/ldoc#403

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see #1999.

@alerque alerque merged commit 3da81a2 into sile-typesetter:develop Feb 13, 2024
19 checks passed
@alerque alerque deleted the ldoc branch February 13, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation bug or improvement issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants