Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加对 EmmyLua table type 的支持 #340

Merged
merged 7 commits into from
Jan 20, 2021
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我限制了下,通过类型名,比如 ‘table’,不会它找到---@type table<k, v> 里的 table。进而导致我这里新加的用例失败。

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