diff options
-rw-r--r-- | script-beta/core/hover/description.lua | 4 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 12 | ||||
-rw-r--r-- | script-beta/parser/luadoc.lua | 27 | ||||
-rw-r--r-- | script-beta/vm/getDocs.lua | 6 | ||||
-rw-r--r-- | test-beta/crossfile/hover.lua | 63 |
5 files changed, 83 insertions, 29 deletions
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua index afe90c05..31d5bf58 100644 --- a/script-beta/core/hover/description.lua +++ b/script-beta/core/hover/description.lua @@ -221,6 +221,10 @@ local function getBindEnums(source) for _, doc in ipairs(source.bindDocs) do if doc.type == 'doc.param' then chunks[#chunks+1] = buildEnumChunk(doc.extends, doc.param[1]) + elseif doc.type == 'doc.return' then + for n, rtn in ipairs(doc.returns) do + chunks[#chunks+1] = buildEnumChunk(rtn, rtn.name and rtn.name[1] or ('(return %d)'):format(n)) + end end end if #chunks == 0 then diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index d5f16486..93961733 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -2625,13 +2625,11 @@ function m.getDocTypeNames(status, doc, genericCallback) source = enum, } end - if doc.resumes then - for _, resume in ipairs(doc.resumes) do - results[#results+1] = { - type = resume[1], - source = resume, - } - end + for _, resume in ipairs(doc.resumes) do + results[#results+1] = { + type = resume[1], + source = resume, + } end return results end diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index 416bce20..83ae940a 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -388,19 +388,12 @@ local function parseResume() end function parseType(parent) - if not peekToken() then - pushError { - type = 'LUADOC_MISS_TYPE_NAME', - start = getFinish(), - finish = getFinish(), - } - return nil - end local result = { - type = 'doc.type', - parent = parent, - types = {}, - enums = {}, + type = 'doc.type', + parent = parent, + types = {}, + enums = {}, + resumes = {}, } while true do local tp, content = peekToken() @@ -442,9 +435,6 @@ function parseType(parent) local nextComm = NextComment('peek') if nextComm and nextComm.text:sub(1, 2) == '-|' then NextComment() - if not result.resumes then - result.resumes = {} - end local finishPos = nextComm.text:find('#', 3) or #nextComm.text parseTokens(nextComm.text:sub(3, finishPos), nextComm.start + 1) local resume = parseResume() @@ -458,7 +448,12 @@ function parseType(parent) end end - if #result.types == 0 and #result.enums == 0 then + if #result.types == 0 and #result.enums == 0 and #result.resumes == 0 then + pushError { + type = 'LUADOC_MISS_TYPE_NAME', + start = getFinish(), + finish = getFinish(), + } return nil end return result diff --git a/script-beta/vm/getDocs.lua b/script-beta/vm/getDocs.lua index b1641cec..3fb0dfc0 100644 --- a/script-beta/vm/getDocs.lua +++ b/script-beta/vm/getDocs.lua @@ -87,10 +87,8 @@ function vm.getDocEnums(doc, mark, results) for _, enum in ipairs(doc.enums) do results[#results+1] = enum end - if doc.resumes then - for _, resume in ipairs(doc.resumes) do - results[#results+1] = resume - end + for _, resume in ipairs(doc.resumes) do + results[#results+1] = resume end for _, unit in ipairs(doc.types) do if unit.type == 'doc.type.name' then diff --git a/test-beta/crossfile/hover.lua b/test-beta/crossfile/hover.lua index 5e915803..fd11481d 100644 --- a/test-beta/crossfile/hover.lua +++ b/test-beta/crossfile/hover.lua @@ -319,7 +319,7 @@ x: string ```]] } } -do return end + TEST { { path = 'a.lua', @@ -336,7 +336,36 @@ TEST { ]] }, hover = { - label = 'function f(x: option)', + label = "function f(x: '选项1'|'选项2')", + name = 'f', + description = [[ +```lua +x: option + | '选项1' -- 注释1 + |>'选项2' -- 注释2 +```]] + } +} + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = [[ + ---@alias option + ---| "'选项1'" # 注释1 + ---| > "'选项2'" # 注释2 + ---@return option x + function <?f?>() end + ]] + }, + hover = { + label = [[ +function f() + -> x: '选项1'|'选项2']], name = 'f', description = [[ ```lua @@ -346,6 +375,36 @@ x: option ```]] } } + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = [[ + ---@alias option + ---| "'选项1'" # 注释1 + ---| > "'选项2'" # 注释2 + ---@return option + function <?f?>() end + ]] + }, + hover = { + label = [[ +function f() + -> '选项1'|'选项2']], + name = 'f', + description = [[ +```lua +(return 1): option + | '选项1' -- 注释1 + |>'选项2' -- 注释2 +```]] + } +} + do return end TEST { { |