diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2022-05-12 16:02:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 08:02:46 -0600 |
commit | a1b663cce861a76f78d65aa538426d0cf635c379 (patch) | |
tree | fa9e34b0021bca3922eb8ffa01f24a4a2a43a3f6 /scripts/lua2dox.lua | |
parent | 2bbd588e73c4c0c17e497fafd281ceba382b9e4d (diff) | |
download | rneovim-a1b663cce861a76f78d65aa538426d0cf635c379.tar.gz rneovim-a1b663cce861a76f78d65aa538426d0cf635c379.tar.bz2 rneovim-a1b663cce861a76f78d65aa538426d0cf635c379.zip |
build(lua2dox): add parenthesis around parameter types in documentation (#18532)
This will check if the string after the variable in a @param is either
"number", "string", "table", "boolean" and "function" and if so add a
parenthesis around it. This will help separate the variable type with
the following text. Had all our functions been annotated with emmylua
then a more robust solution might have been preferable (such as always
assuming the third string is parameter type without making any checks).
I believe however this is a clear improvement over the current situation
and will suffice for now.
Diffstat (limited to 'scripts/lua2dox.lua')
-rw-r--r-- | scripts/lua2dox.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/lua2dox.lua b/scripts/lua2dox.lua index c32370517c..6a206066b8 100644 --- a/scripts/lua2dox.lua +++ b/scripts/lua2dox.lua @@ -403,6 +403,29 @@ function TLua2DoX_filter.readfile(this,AppStamp,Filename) if string.sub(line, 3, 3) == '@' or string.sub(line, 1, 4) == '---@' then -- it's a magic comment state = 'in_magic_comment' local magic = string.sub(line, 4 + offset) + + local magic_split = string_split(magic, ' ') + + local type_index = 2 + if magic_split[1] == 'param' then + type_index = type_index + 1 + end + + if magic_split[type_index] == 'number' or + magic_split[type_index] == 'number|nil' or + magic_split[type_index] == 'string' or + magic_split[type_index] == 'string|nil' or + magic_split[type_index] == 'table' or + magic_split[type_index] == 'table|nil' or + magic_split[type_index] == 'boolean' or + magic_split[type_index] == 'boolean|nil' or + magic_split[type_index] == 'function' or + magic_split[type_index] == 'function|nil' + then + magic_split[type_index] = '(' .. magic_split[type_index] .. ')' + end + magic = table.concat(magic_split, ' ') + outStream:writeln('/// @' .. magic) fn_magic = checkComment4fn(fn_magic,magic) elseif string.sub(line,3,3)=='-' then -- it's a nonmagic doc comment |