diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 17:49:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 17:49:50 +0800 |
commit | efc8d64b34008091573e1746ea6a273b6b50b318 (patch) | |
tree | 04aa7bf903a67cf985c76aba182155e1fe1de7eb /script-beta | |
parent | 57e4aa220078222cde843af7ebaea4b839a6cec3 (diff) | |
download | lua-language-server-efc8d64b34008091573e1746ea6a273b6b50b318.zip |
doc.field support doc.comment
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/hover/description.lua | 30 | ||||
-rw-r--r-- | script-beta/core/hover/init.lua | 9 |
2 files changed, 32 insertions, 7 deletions
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, |