diff options
-rw-r--r-- | script/parser/guide.lua | 2 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 80 | ||||
-rw-r--r-- | test/hover/init.lua | 12 |
3 files changed, 83 insertions, 11 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 780959a3..d88bd2d0 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -129,8 +129,10 @@ m.childMap = { ['doc.type.array'] = {'node'}, ['doc.type.table'] = {'tkey', 'tvalue', 'comment'}, ['doc.type.function'] = {'#args', '#returns', 'comment'}, + ['doc.type.ltable'] = {'#fields'}, ['doc.type.literal'] = {'node'}, ['doc.type.arg'] = {'extends'}, + ['doc.type.field'] = {'extends'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, } diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 83f59366..7a0ae3d1 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -45,19 +45,9 @@ EChar <- 'a' -> ea / ([0-9] [0-9]? [0-9]?) -> Char10 / ('u{' {Word*} '}') -> CharUtf8 Symbol <- ({} { - ':' - / '|' - / ',' + [:|,<>()?+#`{}] / '[]' - / '<' - / '>' - / '(' - / ')' - / '?' / '...' - / '+' - / '#' - / '`' } {}) -> Symbol ]], { @@ -398,6 +388,64 @@ local function parseTypeUnitFunction() return typeUnit end +local function parseTypeUnitLiteralTable(parent) + local typeUnit = { + type = 'doc.type.ltable', + parent = parent, + start = getStart(), + fields = {}, + } + + while true do + if checkToken('symbol', '}', 1) then + nextToken() + break + end + local field = { + type = 'doc.type.field', + parent = typeUnit, + } + + do + field.name = parseName('doc.type.name', field) + if not field.name then + pushError { + type = 'LUADOC_MISS_FIELD_NAME', + start = getFinish(), + finish = getFinish(), + } + break + end + if not field.start then + field.start = field.name.start + end + if checkToken('symbol', '?', 1) then + nextToken() + field.optional = true + end + field.finish = getFinish() + if not nextSymbolOrError(':') then + break + end + field.extends = parseType(field) + if not field.extends then + break + end + field.finish = getFinish() + end + + typeUnit.fields[#typeUnit.fields+1] = field + if checkToken('symbol', ',', 1) then + nextToken() + else + nextSymbolOrError(')') + break + end + end + typeUnit.finish = getFinish() + return typeUnit +end + local function parseTypeUnit(parent, content) local result if content == 'fun' then @@ -515,6 +563,16 @@ function parseType(parent) if not result.start then result.start = typeEnum.start end + elseif tp == 'symbol' and content == '{' then + nextToken() + local typeUnit = parseTypeUnitLiteralTable(result) + if not typeUnit then + break + end + result.types[#result.types+1] = typeUnit + if not result.start then + result.start = typeUnit.start + end elseif tp == 'symbol' and content == '...' then nextToken() local vararg = { diff --git a/test/hover/init.lua b/test/hover/init.lua index d9492fd1..79469b90 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1601,3 +1601,15 @@ local t: Position { z?: number, } ]] + +TEST [[ +---@type { x: string, y: number, z: boolean } +local <?t?> +]] +[[ +local t: { + x: string, + y: number, + z: boolean, +} +]] |