Skip to content

Commit e847882

Browse files
committed
enum[<key>or<index>]时未定义的字段会报未定义
1 parent 2e8a8db commit e847882

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

script/core/diagnostics/undefined-field.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,39 @@ return function (uri, callback)
5252
}
5353
end
5454
end
55+
---@async
56+
local function checkUndefinedFieldByIndexEnum(src)
57+
await.delay()
58+
local isEnum = false
59+
for _, node in ipairs(vm.compileNode(src.node)) do
60+
local docs = node.bindDocs
61+
if docs then
62+
for _, doc in ipairs(docs) do
63+
if doc.type == "doc.enum" then
64+
isEnum = true
65+
break
66+
end
67+
end
68+
end
69+
end
70+
if not isEnum then
71+
return
72+
end
73+
if vm.hasDef(src) then
74+
return
75+
end
76+
local keyName = guide.getKeyName(src)
77+
if not keyName then
78+
return
79+
end
80+
local message = lang.script('DIAG_UNDEF_FIELD', guide.getKeyName(src))
81+
callback {
82+
start = src.index.start,
83+
finish = src.index.finish,
84+
message = message,
85+
}
86+
end
5587
guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField)
5688
guide.eachSourceType(ast.ast, 'getmethod', checkUndefinedField)
89+
guide.eachSourceType(ast.ast, 'getindex', checkUndefinedFieldByIndexEnum)
5790
end

0 commit comments

Comments
 (0)