diff options
-rw-r--r-- | script/parser/guide.lua | 20 | ||||
-rw-r--r-- | script/vm/getDocs.lua | 5 | ||||
-rw-r--r-- | test/definition/luadoc.lua | 10 | ||||
-rw-r--r-- | 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 5264a2b6..d0e82ba8 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<k,v> 中的 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 632dd1c2..790a9b50 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 3c0c764b..5315b5fd 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -331,3 +331,13 @@ for i, v in ipairs(v1) do print(v2.<?bar1?>) end ]] + +TEST [[ +---@class Foo +local Foo = {} +function Foo:<!bar1!>() end + +---@type table<number, table<number, Foo>> +local v1 +print(v1[1][1].<?bar1?>) +]] diff --git a/test/hover/init.lua b/test/hover/init.lua index 35222f32..5b3acded 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1171,7 +1171,7 @@ TEST [[ local <?x?> ]] [[ -local x: table<ClassA, ClassB> {} +local x: table<ClassA, ClassB> ]] --TEST [[ |