docs: remove "#" comment char in @return

Everything after a "#" char is a "description" comment, i.e. luals won't
treat it as a type, name, etc. But "#" should not be present in the
generated docs (such as :help docs).
https://github.com/LuaLS/lua-language-server/wiki/Annotations#return
This commit is contained in:
Justin M. Keyes
2023-08-03 13:41:47 +02:00
parent d2f8133024
commit b1fb04475e
4 changed files with 13 additions and 7 deletions

View File

@ -154,6 +154,8 @@ local function removeCommentFromLine(line)
return line:sub(1, pos_comment - 1), line:sub(pos_comment)
end
--- Processes "@…" directives in a docstring line.
---
--- @param line string
--- @param generics table<string,string>
--- @return string?
@ -206,6 +208,8 @@ local function process_magic(line, generics)
magic = magic:gsub('^return%s+.*%((' .. type .. ')%)', 'return %1')
magic = magic:gsub('^return%s+.*%((' .. type .. '|nil)%)', 'return %1')
end
-- Remove first "#" comment char, if any. https://github.com/LuaLS/lua-language-server/wiki/Annotations#return
magic = magic:gsub('# ', '', 1)
-- handle the return of vim.spell.check
magic = magic:gsub('({.*}%[%])', '`%1`')
magic_split = vim.split(magic, ' ', { plain = true })