diff options
-rw-r--r-- | script/core/completion/completion.lua | 2 | ||||
-rw-r--r-- | script/core/hover/description.lua | 33 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 6 | ||||
-rw-r--r-- | script/vm/global.lua | 4 | ||||
-rw-r--r-- | script/vm/type.lua | 3 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 28 |
6 files changed, 73 insertions, 3 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 01b5fcfe..74490c26 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1567,6 +1567,8 @@ local function tryluaDocCate(word, results) 'nodiscard', 'cast', 'operator', + 'source', + 'enum', } do if matchKey(word, docType) then results[#results+1] = { diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 382404c1..0bfe8cc8 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -412,6 +412,38 @@ local function tyrDocParamComment(source) end end +---@param source parser.object +local function tryDocEnum(source) + if source.type ~= 'doc.enum' then + return + end + local tbl = source.bindSource + if not tbl then + return + end + local md = markdown() + md:add('lua', '{') + for _, field in ipairs(tbl) do + if field.type == 'tablefield' + or field.type == 'tableindex' then + if not field.value then + goto CONTINUE + end + local key = guide.getKeyName(field) + if not key then + goto CONTINUE + end + if field.value.type == 'integer' + or field.value.type == 'string' then + md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1])) + end + ::CONTINUE:: + end + end + md:add('lua', '}') + return md:string() +end + return function (source) if source.type == 'string' then return asString(source) @@ -425,4 +457,5 @@ return function (source) or tryDocComment(source) or tryDocClassComment(source) or tryDocModule(source) + or tryDocEnum(source) end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index b4b311ae..d13120b6 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1646,7 +1646,6 @@ local function bindDoc(source, binded) or doc.type == 'doc.deprecated' or doc.type == 'doc.version' or doc.type == 'doc.module' - or doc.type == 'doc.enum' or doc.type == 'doc.source' then if source.type == 'function' or isParam then @@ -1700,6 +1699,10 @@ local function bindDoc(source, binded) if source.type ~= 'function' then goto CONTINUE end + elseif doc.type == 'doc.enum' then + if source.type ~= 'table' then + goto CONTINUE + end elseif doc.type ~= 'doc.comment' then goto CONTINUE end @@ -1756,6 +1759,7 @@ local function bindDocsBetween(sources, binded, start, finish) or src.type == 'setindex' or src.type == 'setmethod' or src.type == 'function' + or src.type == 'table' or src.type == '...' then if bindDoc(src, binded) then ok = true diff --git a/script/vm/global.lua b/script/vm/global.lua index d9509fe7..c9bb4cc7 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -331,8 +331,8 @@ local compilerGlobalSwitch = util.switch() enum:addSet(uri, source) source._globalNode = enum - local tbl = source.bindSource and source.bindSource.value - if not tbl or tbl.type ~= 'table' then + local tbl = source.bindSource + if not tbl then return end source._enums = {} diff --git a/script/vm/type.lua b/script/vm/type.lua index 30d509ce..5d42de6c 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -52,6 +52,9 @@ local function checkEnum(parentName, child, uri) end for _, set in ipairs(parentClass:getSets(uri)) do if set.type == 'doc.enum' then + if not set._enums then + return false + end if child.type ~= 'string' and child.type ~= 'doc.type.string' and child.type ~= 'integer' diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 60a962e9..d1148309 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -1497,3 +1497,31 @@ A: | 2 -- comment2 ```]] } + +TEST { + { + path = 'a.lua', + content = [[ + ---@enum <?A?> + local t = { + x = 1, + y = 2, + z = 3, + } + ]] + }, + hover = [[ +```lua +(enum) A +``` + +--- + +```lua +{ + x: integer = 1, + y: integer = 2, + z: integer = 3, +} +```]] +} |