From 217aa4e586b1786bc6b82828279b745a29290f4d Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Tue, 5 Jan 2021 20:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=89=A9=E5=B1=95=20getArray?= =?UTF-8?q?Level=20=E6=9D=A5=E6=89=BE=E5=88=B0=E5=B1=82=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/parser/guide.lua | 20 +++++++++++++------- script/vm/getDocs.lua | 5 +++++ test/definition/luadoc.lua | 10 ++++++++++ test/hover/init.lua | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 5264a2b67..d0e82ba8a 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1663,12 +1663,20 @@ function m.checkSameSimpleOfRefByDocSource(status, obj, start, pushQueue, mode) end end -local function getArrayLevel(obj) +local function getArrayOrTableLevel(obj) local level = 0 while true do local parent = obj.parent if parent.type == 'doc.type.array' then level = level + 1 + elseif parent.type == 'doc.type.table' then + if obj.type == 'doc.type' then + level = level + 1 + -- else 只存在 obj.type == 'doc.type.name' 的情况,即 table 中的 table,这种是不需要再增加层级的 + end + elseif parent.type == 'doc.type' and parent.parent and parent.parent.type == 'doc.type.table' then + level = level + 1 + parent = parent.parent else break end @@ -1725,12 +1733,10 @@ function m.checkSameSimpleByDoc(status, obj, start, pushQueue, mode) for _, res in ipairs(pieceResult) do pushQueue(res, start, true) end - 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 - getArrayLevel(obj), pushQueue, mode) - end + + local state = m.getDocState(obj) + if state.type == 'doc.type' and mode == 'ref' then + m.checkSameSimpleOfRefByDocSource(status, state, start - getArrayOrTableLevel(obj), pushQueue, mode) end return true elseif obj.type == 'doc.field' then diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 632dd1c28..790a9b50d 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -16,6 +16,11 @@ local function getTypesOfFile(uri) or src.type == 'doc.class.name' or src.type == 'doc.extends.name' or src.type == 'doc.alias.name' then + if src.type == 'doc.type.name' then + if guide.getParentDocTypeTable(src) then + return + end + end local name = src[1] if name then if not types[name] then diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua index 3c0c764bc..5315b5fd6 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -331,3 +331,13 @@ for i, v in ipairs(v1) do print(v2.) end ]] + +TEST [[ +---@class Foo +local Foo = {} +function Foo:() end + +---@type table> +local v1 +print(v1[1][1].) +]] diff --git a/test/hover/init.lua b/test/hover/init.lua index 35222f32d..5b3acded2 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1171,7 +1171,7 @@ TEST [[ local ]] [[ -local x: table {} +local x: table ]] --TEST [[