summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/infer.lua3
-rw-r--r--script/core/noder.lua32
-rw-r--r--script/core/searcher.lua9
-rw-r--r--script/core/type-definition.lua3
-rw-r--r--script/parser/guide.lua6
-rw-r--r--script/parser/luadoc.lua2
-rw-r--r--test/definition/luadoc.lua7
7 files changed, 59 insertions, 3 deletions
diff --git a/script/core/infer.lua b/script/core/infer.lua
index ef3076b7..ed802a58 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -381,6 +381,9 @@ function m.getDocName(doc)
local value = doc[1] or '?'
return value
end
+ if doc.type == 'doc.type.ltable' then
+ return 'table'
+ end
end
function m.viewDocFunction(doc)
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 42079a9c..eac1b9f5 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -218,6 +218,10 @@ local function getKey(source)
return 'de:' .. source.start
elseif source.type == 'doc.type.table' then
return 'dtable:' .. source.start
+ elseif source.type == 'doc.type.ltable' then
+ return 'dltable:' .. source.start
+ elseif source.type == 'doc.type.field' then
+ return 'dfield:' .. source.start
elseif source.type == 'doc.type.array' then
return 'darray:' .. source.start
elseif source.type == 'doc.type.function' then
@@ -830,6 +834,31 @@ function m.compileNode(noders, source)
pushForward(noders, valueID, getID(source.tvalue))
end
end
+ if source.type == 'doc.type.ltable' then
+ local firstField = source.fields[1]
+ if not firstField then
+ return
+ end
+ local keyID = ('%s%s'):format(
+ id,
+ WEAK_TABLE_KEY
+ )
+ local valueID = ('%s%s'):format(
+ id,
+ WEAK_ANY_FIELD
+ )
+ pushForward(noders, keyID, 'dn:string')
+ pushForward(noders, valueID, getID(firstField.extends))
+ for _, field in ipairs(source.fields) do
+ local extendsID = ('%s%s%q'):format(
+ id,
+ SPLIT_CHAR,
+ field.name[1]
+ )
+ pushForward(noders, extendsID, getID(field))
+ pushForward(noders, extendsID, getID(field.extends))
+ end
+ end
if source.type == 'doc.type.array' then
if source.node then
local nodeID = ('%s%s'):format(
@@ -1061,6 +1090,9 @@ function m.compileNode(noders, source)
pushForward(noders, valueID, getID(source.tvalue))
end
end
+ if proto.type == 'doc.type.ltable' then
+ -- TODO
+ end
end
end
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 550fadfd..fa70ab35 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -71,6 +71,8 @@ function m.pushResult(status, mode, source, force)
or source.type == 'doc.resume'
or source.type == 'doc.type.array'
or source.type == 'doc.type.table'
+ or source.type == 'doc.type.ltable'
+ or source.type == 'doc.type.field'
or source.type == 'doc.type.function' then
results[#results+1] = source
return
@@ -117,6 +119,8 @@ function m.pushResult(status, mode, source, force)
or source.type == 'doc.resume'
or source.type == 'doc.type.array'
or source.type == 'doc.type.table'
+ or source.type == 'doc.type.ltable'
+ or source.type == 'doc.type.field'
or source.type == 'doc.type.function' then
results[#results+1] = source
return
@@ -767,6 +771,11 @@ local function getField(status, source, mode)
end
return
end
+ if source.type == 'doc.type.ltable' then
+ for _, field in ipairs(source.fields) do
+ m.pushResult(status, mode, field)
+ end
+ end
if source.type == 'doc.class.name' then
local class = source.parent
for _, field in ipairs(class.fields) do
diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua
index abfe525b..4dd9ac32 100644
--- a/script/core/type-definition.lua
+++ b/script/core/type-definition.lua
@@ -156,7 +156,8 @@ return function (uri, offset)
or src.type == 'doc.alias.name'
or src.type == 'doc.type.function'
or src.type == 'doc.type.array'
- or src.type == 'doc.type.table' then
+ or src.type == 'doc.type.table'
+ or src.type == 'doc.type.ltable' then
results[#results+1] = {
target = src,
uri = files.getOriginUri(root.uri),
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index d88bd2d0..2508b801 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -129,7 +129,7 @@ m.childMap = {
['doc.type.array'] = {'node'},
['doc.type.table'] = {'tkey', 'tvalue', 'comment'},
['doc.type.function'] = {'#args', '#returns', 'comment'},
- ['doc.type.ltable'] = {'#fields'},
+ ['doc.type.ltable'] = {'#fields', 'comment'},
['doc.type.literal'] = {'node'},
['doc.type.arg'] = {'extends'},
['doc.type.field'] = {'extends'},
@@ -877,6 +877,8 @@ function m.getKeyName(obj)
return obj.field[1]
elseif tp == 'doc.field.name' then
return obj[1]
+ elseif tp == 'doc.type.field' then
+ return obj.name[1]
elseif tp == 'dummy' then
return obj[1]
end
@@ -935,6 +937,8 @@ function m.getKeyType(obj)
return 'string'
elseif tp == 'doc.field' then
return 'string'
+ elseif tp == 'doc.type.field' then
+ return 'string'
elseif tp == 'dummy' then
return 'string'
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 7a0ae3d1..45e59fe9 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -407,7 +407,7 @@ local function parseTypeUnitLiteralTable(parent)
}
do
- field.name = parseName('doc.type.name', field)
+ field.name = parseName('doc.ltfield.name', field)
if not field.name then
pushError {
type = 'LUADOC_MISS_FIELD_NAME',
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 65ded319..34d24cf2 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -645,3 +645,10 @@ TEST [[
local z
z.<?a?>
]]
+
+TEST [[
+---@type { <!x: number!>, y: number }
+local t
+
+print(t.<?x?>)
+]]