summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuhuanzy <501417909@qq.com>2024-08-18 17:40:36 +0800
committerxuhuanzy <501417909@qq.com>2024-08-18 17:40:36 +0800
commite8478829396f9b5ca1fe84e0d616954425c8dd85 (patch)
tree966e91e876c6e400b7d10a33b0c44833de31699f
parent2e8a8db31615db610658d74c5c2f29f30d30073b (diff)
downloadlua-language-server-e8478829396f9b5ca1fe84e0d616954425c8dd85.zip
`enum[<key>or<index>]`时未定义的字段会报未定义
-rw-r--r--script/core/diagnostics/undefined-field.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua
index ab5d4d54..edb65909 100644
--- a/script/core/diagnostics/undefined-field.lua
+++ b/script/core/diagnostics/undefined-field.lua
@@ -52,6 +52,39 @@ return function (uri, callback)
}
end
end
+ ---@async
+ local function checkUndefinedFieldByIndexEnum(src)
+ await.delay()
+ local isEnum = false
+ for _, node in ipairs(vm.compileNode(src.node)) do
+ local docs = node.bindDocs
+ if docs then
+ for _, doc in ipairs(docs) do
+ if doc.type == "doc.enum" then
+ isEnum = true
+ break
+ end
+ end
+ end
+ end
+ if not isEnum then
+ return
+ end
+ if vm.hasDef(src) then
+ return
+ end
+ local keyName = guide.getKeyName(src)
+ if not keyName then
+ return
+ end
+ local message = lang.script('DIAG_UNDEF_FIELD', guide.getKeyName(src))
+ callback {
+ start = src.index.start,
+ finish = src.index.finish,
+ message = message,
+ }
+ end
guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField)
guide.eachSourceType(ast.ast, 'getmethod', checkUndefinedField)
+ guide.eachSourceType(ast.ast, 'getindex', checkUndefinedFieldByIndexEnum)
end