From c08d501b7bdea16d87998d3ef28c2b708515cd10 Mon Sep 17 00:00:00 2001 From: actboy168 Date: Thu, 3 Dec 2020 11:51:01 +0800 Subject: =?UTF-8?q?hover=E5=B0=8A=E9=87=8Dluadoc=E4=B8=AD=E5=90=84?= =?UTF-8?q?=E9=A1=B9=E7=9A=84=E6=AC=A1=E5=BA=8F=EF=BC=8C=E9=99=A4=E4=BA=86?= =?UTF-8?q?enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/core/hover/description.lua | 98 +++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'script') diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index d6450fd3..7be50947 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -187,76 +187,59 @@ local function tryDocFieldUpComment(source) return comment end -local function getBindParamComments(source, bindDocs) - if not isFunction(source) then - return +local function getFunctionComment(source) + local docGroup = source.bindDocs + + local has_return_comment = false + for _, doc in ipairs(docGroup) do + if doc.type == 'doc.return' and doc.comment then + has_return_comment = true + break + end end local comments = {} - for _, doc in ipairs(bindDocs) do - if doc.type == 'doc.param' then + for _, doc in ipairs(docGroup) do + if doc.type == 'doc.comment' then + comments[#comments+1] = doc.comment.text:sub(2) + elseif doc.type == 'doc.param' then if doc.comment then comments[#comments+1] = ('@*param* `%s` — %s'):format( doc.param[1], doc.comment.text ) end - end - end - if #comments == 0 then - return nil - end - return table.concat(comments, '\n\n') -end - -local function getBindReturnComments(source, bindDocs) - if not isFunction(source) then - return - end - - local comments = {} - local index = 0 - for _, doc in ipairs(bindDocs) do - if doc.type == 'doc.return' then - for _, rtn in ipairs(doc.returns) do - index = index + 1 - if doc.comment then - local name = rtn.name and rtn.name[1] or ('#' .. index) + elseif doc.type == 'doc.return' then + if has_return_comment and doc.comment then + local name = {} + for _, rtn in ipairs(doc.returns) do + if rtn.name then + name[#name+1] = rtn.name[1] + end + end + if #name == 0 then + comments[#comments+1] = ('@*return* — %s'):format( + doc.comment.text + ) + else comments[#comments+1] = ('@*return* `%s` — %s'):format( - name, + table.concat(name, ','), doc.comment.text ) end end end end - if #comments == 0 then - return nil - end - return table.concat(comments, '\n\n') -end + comments = table.concat(comments, "\n\n") -local function tryDocComment(source) - if not source.bindDocs then - return - end - local comment = getBindComment(source, source.bindDocs) - local params = getBindParamComments(source, source.bindDocs) - local returns = getBindReturnComments(source, source.bindDocs) - local enums = getBindEnums(source, source.bindDocs) - if not comment and not params and not returns and not enums then + local enums = getBindEnums(source, docGroup) + if comments == "" and not enums then return end local md = markdown() md:add('md', "---") - if comment then - md:add('md', comment) - end - if params then - md:add('md', params) - end - if returns then - md:add('md', returns) + if comments ~= "" then + md:add('md', comments) end if enums then md:add('lua', enums) @@ -264,6 +247,23 @@ local function tryDocComment(source) return md:string() end +local function tryDocComment(source) + if not source.bindDocs then + return + end + if not isFunction(source) then + local comment = getBindComment(source, source.bindDocs) + if not comment then + return + end + local md = markdown() + md:add('md', "---") + md:add('md', comment) + return md:string() + end + return getFunctionComment(source) +end + local function tryDocOverloadToComment(source) if source.type ~= 'doc.type.function' then return -- cgit v1.2.3