Skip to content

Commit

Permalink
通过扩展 getArrayLevel 来找到层级
Browse files Browse the repository at this point in the history
  • Loading branch information
uhziel committed Jan 5, 2021
1 parent eb87cc8 commit 217aa4e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
20 changes: 13 additions & 7 deletions script/parser/guide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions script/vm/getDocs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/definition/luadoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?>)
]]
2 changes: 1 addition & 1 deletion test/hover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ TEST [[
local <?x?>
]]
[[
local x: table<ClassA, ClassB> {}
local x: table<ClassA, ClassB>
]]

--TEST [[
Expand Down

0 comments on commit 217aa4e

Please sign in to comment.