From efc8d64b34008091573e1746ea6a273b6b50b318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 20 Nov 2020 17:49:50 +0800 Subject: doc.field support doc.comment --- script-beta/core/hover/description.lua | 30 +++++++++++++++++++++++------- script-beta/core/hover/init.lua | 9 +++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) (limited to 'script-beta') diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua index dd04373e..c421e3b6 100644 --- a/script-beta/core/hover/description.lua +++ b/script-beta/core/hover/description.lua @@ -184,13 +184,17 @@ local function tryLibrary(source) return md:string() end -local function getBindComment(source) +local function getBindComment(docGroup, base) local lines = {} - for _, doc in ipairs(source.bindDocs) do + for _, doc in ipairs(docGroup) do if doc.type == 'doc.comment' then lines[#lines+1] = doc.comment.text:sub(2) - elseif #lines > 0 then + elseif #lines > 0 and not base then break + elseif doc == base then + break + else + lines = {} end end if #lines == 0 then @@ -222,11 +226,11 @@ local function buildEnumChunk(docType, name) return table.concat(lines, '\n') end -local function getBindEnums(source) +local function getBindEnums(docGroup) local mark = {} local chunks = {} local returnIndex = 0 - for _, doc in ipairs(source.bindDocs) do + for _, doc in ipairs(docGroup) do if doc.type == 'doc.param' then local name = doc.param[1] if mark[name] then @@ -253,12 +257,23 @@ local function getBindEnums(source) return table.concat(chunks, '\n\n') end +local function tryDocFieldUpComment(source) + if source.type ~= 'doc.field' then + return + end + if not source.bindGroup then + return + end + local comment = getBindComment(source.bindGroup, source) + return comment +end + local function tryDocComment(source) if not source.bindDocs then return end - local comment = getBindComment(source) - local enums = getBindEnums(source) + local comment = getBindComment(source.bindDocs) + local enums = getBindEnums(source.bindDocs) local md = markdown() if comment then md:add('md', comment) @@ -292,5 +307,6 @@ return function (source) end return tryLibrary(source) or tryDocOverloadToComment(source) + or tryDocFieldUpComment(source) or tryDocComment(source) end diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index a332cec0..96e01ab5 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -94,6 +94,15 @@ local function getHoverAsValue(source) or source.type == 'setmethod' local label = getLabel(source, oop) local desc = getDesc(source) + if not desc then + local values = vm.getDefs(source, 'deep') + for _, def in ipairs(values) do + desc = getDesc(def) + if desc then + break + end + end + end return { label = label, source = source, -- cgit v1.2.3