Closed lewis6991 closed 1 year ago
Do we need to go through doxygen? It starts sounding like our own custom translator (that only supports the features we need, not all of doxygen) would be the simpler and more maintainable option.
Either that or switch to something else.
One of the things good about doxygen is that it parses the comments pretty well into xml, which is most of the heavy lifting of gen_vimdoc.py
.
I can't find any standard comment parser which would be a good alternative to doxygen. So if we want to use something else, the only Idea I have would be to create an emmy TS parser which can be injected into comments of any language. This would be a fair amount of work but would give us absolute flexibility.
an emmy TS parser which can be injected into comments of any language.
That sounds indeed like a worthwhile and very useful alternative. Note that there is already a tree-sitter-comment parser which nvim-treesitter uses for injections and could be extended in this direction.
Specifically for Lua, there's of course https://github.com/tjdevries/tree-sitter-lua, which has an explicit focus on docgen.
(Not saying that this is the direction we should be pursuing, and now, mind you!)
We could create runtime/lua/types.lua
. This file would never actually be required
. We could even add an error
on top to be sure.
In that file, we can then add the manual docs from lua.txt
with the correct functions.
Doing it this way, we have:
lua-language-server
can pick up those annotations and provide completionsWould definitely make my work with lua-dev.nvim easier.
Right now, I'm parsing the doc/lua.txt
files and then regenerate the lua source automatcially. (with a lot of limitations)
See the generated file below. Could be a good starting point, since it literally includes the docs from doc/lua.txt
.
These are only the functions that don't actually exist in the lua code, so the manual ones from doc/lua.txt
Similar files are created for vim.fn
, vim.api
, vim options
, vim.uv
Avoiding doxygen is orthogonal to the original topic here.
Right now, I'm parsing the doc/lua.txt files and then regenerate the lua source automatcially. (with a lot of limitations)
See the generated file below. Could be a good starting point, since it literally includes the docs from
doc/lua.txt
.
yeah, that is similar to this dummy function for the similar purpose: https://github.com/neovim/neovim/blob/26c653718097955dc4dfbeb45ab602c8dbe9dea5/runtime/lua/vim/shared.lua#L20
seems like a fine way to go. It keeps the docs well-formatted. Manually writing :help docs should be avoided for APIs. And :help as a format should "wither on the vine" as we increment towards https://github.com/neovim/neovim/issues/329 .
I would like to have a go with this. Couple questions before I start:
vim.fn
, vim.api
, vim options
, vim.uv
in multiple files or put it all in one (types.lua
)?runtime/doc/lua.txt
to .lua
files? Such that lua.txt
can be completely generated?I now see that neodev.nvim
basically already has these lua files. Would it be possible to use these?
We need to develop a custom parser so we can extract the documentation from source. AFAIK there aren't any good open source ones so I think we need a custom one.
The current approach uses doxygen + gen_help.py + lua2dox all of which have limitations.
I'm currently working on an lpeg parser which can replace much of the fragile pattern logic in lua2dox. Once that's in place, we'd be in a much stronger position to heavily refactor and simplify the doxygen + gen_help.py flow (and maybe even replace it), as it would be easy enough to extend that to C.
As mentioned above, the other alternative is to use a treesitter based solution, however I think that's a little less straight forward and might be less flexible.
I now see that neodev.nvim basically already has these lua files. Would it be possible to use these?
I not sure how usable that is, some of it might be.
fwiw I already created an emmylua parser for lemmy-help (vimdoc generator). IDK how useful it is to nvim-core in its current state, but I am willing to work on it to adapt to the needs.
I did take a look at that, however I don't think we can use it since it's implemented in rust.
I'm currently aiming for an lpeg based solution since lpeg is pretty good and flexible and we're already using it for the API dispatch.
@lewis6991 there's also the new https://github.com/amaanq/tree-sitter-luadoc by @amaanq.
I'm pretty sure it has everything that's needed for doc gen
We also need to support C
Is it still doxygen? I can write a parser for that
Done in #24363.
For now we will just manually maintain files in runtime/lua/vim/_meta
.
Half of
lua.txt
is manually maintained, and half of it is generated via doxygen. More modules should be generated with the source docs moving to the implementation.This will further the goal of #329
Files to target:
_meta.lua
src/nvim/lua/*.lua
(vim.diff
,vim.mpack
, etc)Problems to solve
Support Lua-C functions
e.g.
nlua_xdl_diff
maps tovim.diff
, however there is currently no (easy) way give this information to doxygen.We can implement doxygen filter which renames the function. e.g.
int nlua_xdl_diff(lua_State *lstate)
->vim.diff(a, b, opts)
. This will be very similar to whatlua2dox.lua
does currently.Support other things than functions
lua2dox currently only supports documenting functions. We can add support so it can document any lua object for things like
vim.bo
,vim.g
,vim.wo
, etc.