summaryrefslogtreecommitdiff
path: root/script/parser/guide.lua
diff options
context:
space:
mode:
authorLei Zhu <uhziel@gmail.com>2020-12-29 19:37:21 +0800
committerLei Zhu <uhziel@gmail.com>2020-12-29 19:37:21 +0800
commit42f9c7d02d6062ce7216abc1489f7a48761cd574 (patch)
tree8ff0a4ed5bd557f9804628fbb8ccc277a6982475 /script/parser/guide.lua
parent248ca2a2ba50f2c059d8ab2d3d5688584e98bf62 (diff)
downloadlua-language-server-42f9c7d02d6062ce7216abc1489f7a48761cd574.zip
提交对 doc.type.map 支持的初版,可以处理推导 v1[1].bar1 的情况
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r--script/parser/guide.lua36
1 files changed, 29 insertions, 7 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index a6149dd7..93c6ffbb 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -95,7 +95,7 @@ m.childMap = {
['doc.generic'] = {'#generics', 'comment'},
['doc.generic.object'] = {'generic', 'extends', 'comment'},
['doc.vararg'] = {'vararg', 'comment'},
- ['doc.type.table'] = {'key', 'value', 'comment'},
+ ['doc.type.table'] = {'node', 'key', 'value', 'comment'},
['doc.type.function'] = {'#args', '#returns', 'comment'},
['doc.type.typeliteral'] = {'node'},
['doc.overload'] = {'overload', 'comment'},
@@ -167,6 +167,21 @@ function m.getParentFunction(obj)
return nil
end
+--- 寻找父的table类型 doc.type.table
+function m.getParentDocTypeTable(obj)
+ for _ = 1, 1000 do
+ local parent = obj.parent
+ if not parent then
+ return nil
+ end
+ if parent.type == 'doc.type.table' then
+ return obj
+ end
+ obj = parent
+ end
+ error('guide.getParentDocTypeTable overstack')
+end
+
--- 寻找所在区块
function m.getBlock(obj)
for _ = 1, 1000 do
@@ -1686,9 +1701,12 @@ function m.checkSameSimpleByDoc(status, obj, start, pushQueue, mode)
for _, res in ipairs(pieceResult) do
pushQueue(res, start, true)
end
- local state = m.getDocState(obj)
- if state.type == 'doc.type' and mode == 'ref' then
- m.checkSameSimpleOfRefByDocSource(status, state, start, pushQueue, mode)
+ local parentDocTypeTable = m.getParentDocTypeTable(obj)
+ if not parentDocTypeTable then
+ local state = m.getDocState(obj)
+ if state.type == 'doc.type' and mode == 'ref' then
+ m.checkSameSimpleOfRefByDocSource(status, state, start, pushQueue, mode)
+ end
end
return true
elseif obj.type == 'doc.field' then
@@ -1699,6 +1717,10 @@ function m.checkSameSimpleByDoc(status, obj, start, pushQueue, mode)
elseif obj.type == 'doc.type.array' then
pushQueue(obj.node, start + 1, true)
return true
+ elseif obj.type == 'doc.type.table' then
+ pushQueue(obj.node, start + 1, true)
+ pushQueue(obj.value, start + 1, true)
+ return true
end
end
@@ -2812,7 +2834,7 @@ function m.viewInferType(infers)
or src.type == 'doc.class.name'
or src.type == 'doc.type.name'
or src.type == 'doc.type.array'
- or src.type == 'doc.type.generic' then
+ or src.type == 'doc.type.table' then
if infer.type ~= 'any' then
hasDoc = true
break
@@ -2827,7 +2849,7 @@ function m.viewInferType(infers)
or src.type == 'doc.class.name'
or src.type == 'doc.type.name'
or src.type == 'doc.type.array'
- or src.type == 'doc.type.generic'
+ or src.type == 'doc.type.table'
or src.type == 'doc.type.enum'
or src.type == 'doc.resume' then
local tp = infer.type or 'any'
@@ -3056,7 +3078,7 @@ function m.getDocTypeUnitName(status, unit)
typeName = 'function'
elseif unit.type == 'doc.type.array' then
typeName = m.getDocTypeUnitName(status, unit.node) .. '[]'
- elseif unit.type == 'doc.type.generic' then
+ elseif unit.type == 'doc.type.table' then
typeName = ('%s<%s, %s>'):format(
m.getDocTypeUnitName(status, unit.node),
m.viewInferType(m.getDocTypeNames(status, unit.key)),