diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-11 13:24:00 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-11 13:24:00 +0800 |
commit | d4c83bca160fd4215aad241f466bb2485d9e00e5 (patch) | |
tree | bbca4ba9e3f1b9136a2d539fa08086c208321b8b /script-beta/core | |
parent | c226b214cbbf23a39ec3a065c9cadc5e17acd883 (diff) | |
download | lua-language-server-d4c83bca160fd4215aad241f466bb2485d9e00e5.zip |
doc.resume
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/hover/description.lua | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua index dfb260b0..afe90c05 100644 --- a/script-beta/core/hover/description.lua +++ b/script-beta/core/hover/description.lua @@ -180,14 +180,7 @@ local function tryLibrary(source) return md:string() end -local function tryDocComment(source) - if source.type == 'field' - or source.type == 'method' then - source = source.parent - end - if not source.bindDocs then - return - end +local function getBindComment(source) local lines = {} for _, doc in ipairs(source.bindDocs) do if doc.type == 'doc.comment' then @@ -197,10 +190,62 @@ local function tryDocComment(source) end end if #lines == 0 then + return nil + end + return table.concat(lines, '\n') +end + +local function buildEnumChunk(docType, name) + local enums = vm.getDocEnums(docType) + if #enums == 0 then + return + end + local types = {} + for _, tp in ipairs(docType.types) do + types[#types+1] = tp[1] + end + local lines = {} + lines[#lines+1] = ('%s: %s'):format(name, table.concat(types)) + for _, enum in ipairs(enums) do + lines[#lines+1] = (' |%s%s%s'):format( + enum.default and '>' or ' ', + enum[1], + enum.comment and (' -- %s'):format(enum.comment) or '' + ) + end + return table.concat(lines, '\n') +end + +local function getBindEnums(source) + local chunks = {} + for _, doc in ipairs(source.bindDocs) do + if doc.type == 'doc.param' then + chunks[#chunks+1] = buildEnumChunk(doc.extends, doc.param[1]) + end + end + if #chunks == 0 then + return nil + end + return table.concat(chunks, '\n\n') +end + +local function tryDocComment(source) + if source.type == 'field' + or source.type == 'method' then + source = source.parent + end + if not source.bindDocs then return end + local comment = getBindComment(source) + local enums = getBindEnums(source) local md = markdown() - md:add('md', table.concat(lines, '\n')) + if comment then + md:add('md', comment) + end + if enums then + md:add('lua', enums) + end return md:string() end |