From 862e4f06beb191bacc6db42f2592abc2851dd87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 6 Apr 2021 18:04:25 +0800 Subject: fix #495 --- script/core/hover/description.lua | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'script/core') diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 3766d2f4..72ff561f 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -244,22 +244,33 @@ local function getFunctionComment(source) end local comments = {} + local isComment = true for _, doc in ipairs(docGroup) do if doc.type == 'doc.comment' then + if not isComment then + comments[#comments+1] = '\n' + end + isComment = true if doc.comment.text:sub(1, 1) == '-' then comments[#comments+1] = doc.comment.text:sub(2) else comments[#comments+1] = doc.comment.text end + comments[#comments+1] = '\n' elseif doc.type == 'doc.param' then if doc.comment then + isComment = false + comments[#comments+1] = '\n' comments[#comments+1] = ('@*param* `%s` — %s'):format( doc.param[1], doc.comment.text:gsub('[\r\n]+', ' ') ) + comments[#comments+1] = '\n' end elseif doc.type == 'doc.return' then if hasReturnComment then + isComment = false + comments[#comments+1] = '\n' local name = {} for _, rtn in ipairs(doc.returns) do if rtn.name then @@ -279,24 +290,27 @@ local function getFunctionComment(source) comments[#comments+1] = ('@*return* `%s`'):format(table.concat(name, ',')) end end + comments[#comments+1] = '\n' end elseif doc.type == 'doc.overload' then comments[#comments+1] = '---' end end - comments = table.concat(comments, "\n\n") + if comments[1] == '\n' then + table.remove(comments, 1) + end + if comments[#comments] == '\n' then + table.remove(comments) + end + comments = table.concat(comments) local enums = getBindEnums(source, docGroup) - if comments == "" and not enums then + if comments == '' and not enums then return end local md = markdown() - if comments ~= "" then - md:add('md', comments) - end - if enums then - md:add('lua', enums) - end + md:add('md', comments) + md:add('lua', enums) return md:string() end -- cgit v1.2.3