diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/hover/description.lua | 59 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 55 |
2 files changed, 74 insertions, 40 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index a8e98b29..d081aa7f 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -6,6 +6,7 @@ local guide = require 'core.guide' local markdown = require 'provider.markdown' local config = require 'config' local lang = require 'language' +local util = require 'utility' local function asStringInRequire(source, literal) local rootPath = ws.path or '' @@ -121,6 +122,28 @@ local function getBindComment(source, docGroup, base) return table.concat(lines, '\n') end +local function tryDocClassComment(source) + for _, def in ipairs(vm.getDefs(source, 0)) do + if def.type == 'doc.class.name' + or def.type == 'doc.alias.name' then + local class = guide.getDocState(def) + local comment = getBindComment(class, class.bindGroup, class) + if comment then + return comment + end + end + end + if source.bindDocs then + for _, doc in ipairs(source.bindDocs) do + if doc.type == 'doc.class' + or doc.type == 'doc.alias' then + local comment = getBindComment(doc, source.bindDocs, doc) + return comment + end + end + end +end + local function buildEnumChunk(docType, name) local enums = vm.getDocEnums(docType) if not enums or #enums == 0 then @@ -131,6 +154,14 @@ local function buildEnumChunk(docType, name) types[#types+1] = tp[1] end local lines = {} + for _, typeUnit in ipairs(docType.types) do + local comment = tryDocClassComment(typeUnit) + if comment then + for line in util.eachLine(comment) do + lines[#lines+1] = ('-- %s'):format(line) + end + end + end lines[#lines+1] = ('%s: %s'):format(name, table.concat(types)) for _, enum in ipairs(enums) do lines[#lines+1] = (' %s %s%s'):format( @@ -138,7 +169,7 @@ local function buildEnumChunk(docType, name) or (enum.additional and '+>') or ' |', enum[1], - enum.comment and (' -- %s'):format(enum.comment) or '' + enum.comment and (' -- %s'):format(enum.comment:gsub('[\r\n]+', ' ')) or '' ) end return table.concat(lines, '\n') @@ -224,7 +255,7 @@ local function getFunctionComment(source) if doc.comment then comments[#comments+1] = ('@*param* `%s` — %s'):format( doc.param[1], - doc.comment.text + doc.comment.text:gsub('[\r\n]+', ' ') ) end elseif doc.type == 'doc.return' then @@ -237,9 +268,9 @@ local function getFunctionComment(source) end if doc.comment then if #name == 0 then - comments[#comments+1] = ('@*return* — %s'):format(doc.comment.text) + comments[#comments+1] = ('@*return* — %s'):format(doc.comment.text:gsub('[\r\n]+', ' ')) else - comments[#comments+1] = ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text) + comments[#comments+1] = ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text:gsub('[\r\n]+', ' ')) end else if #name == 0 then @@ -269,26 +300,6 @@ local function getFunctionComment(source) return md:string() end -local function tryDocClassComment(source) - for _, def in ipairs(vm.getDefs(source, 0)) do - if def.type == 'doc.class.name' then - local class = guide.getDocState(def) - local comment = getBindComment(class, class.bindGroup, class) - if comment then - return comment - end - end - end - if source.bindDocs then - for _, doc in ipairs(source.bindDocs) do - if doc.type == 'doc.class' then - local comment = getBindComment(doc, source.bindDocs, doc) - return comment - end - end - end -end - local function tryDocComment(source) if not source.bindDocs then return diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 1b48719d..aa258932 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -455,6 +455,7 @@ local function parseResume() return result end +local LastType function parseType(parent) local result = { type = 'doc.type', @@ -543,23 +544,45 @@ function parseType(parent) result.finish = getFinish() result.firstFinish = result.finish - while true do - local nextComm = NextComment('peek') - if nextComm and nextComm.text:sub(1, 2) == '-|' then - NextComment() - local finishPos = nextComm.text:find('#', 3) or #nextComm.text - parseTokens(nextComm.text:sub(3, finishPos), nextComm.start + 1) - local resume = parseResume() - if resume then - resume.comment = nextComm.text:match('#%s*(.+)', 3) - result.resumes[#result.resumes+1] = resume - result.finish = resume.finish + local function pushResume() + local comments + for i = 0, 100 do + local nextComm = NextComment(i,'peek') + if not nextComm then + return false + end + if nextComm.text:sub(1, 2) == '-@' then + return false + else + if nextComm.text:sub(1, 2) == '-|' then + NextComment(i) + local finishPos = nextComm.text:find('#', 3) or #nextComm.text + parseTokens(nextComm.text:sub(3, finishPos), nextComm.start + 1) + local resume = parseResume() + if resume then + if comments then + resume.comment = table.concat(comments, '\n') + else + resume.comment = nextComm.text:match('#%s*(.+)', 3) + end + result.resumes[#result.resumes+1] = resume + result.finish = resume.finish + end + comments = nil + return true + else + if not comments then + comments = {} + end + comments[#comments+1] = nextComm.text:sub(2) + end end - else - break end + return false end + while pushResume() do end + if #result.types == 0 and #result.enums == 0 and #result.resumes == 0 then pushError { type = 'LUADOC_MISS_TYPE_NAME', @@ -1215,10 +1238,10 @@ return function (_, state) pushError = state.pushError local ci = 1 - NextComment = function (peek) - local comment = comments[ci] + NextComment = function (offset, peek) + local comment = comments[ci + (offset or 0)] if not peek then - ci = ci + 1 + ci = ci + 1 + (offset or 0) end return comment end |