diff options
author | uhziel <uhziel@gmail.com> | 2020-12-10 14:27:08 +0800 |
---|---|---|
committer | uhziel <uhziel@gmail.com> | 2020-12-10 14:27:08 +0800 |
commit | c06cda864aff2e9c17a5e71c8b48c98b8a0c7e4e (patch) | |
tree | 3fdb729ed95e4040331d67fb9e0fa2214e0658d4 /script/core/diagnostics/undefined-field.lua | |
parent | 40485201209974f79f8ecfc8ffc12352c41b56fc (diff) | |
download | lua-language-server-c06cda864aff2e9c17a5e71c8b48c98b8a0c7e4e.zip |
只对类的field做undefined-field诊断,避免检测出过多干扰性问题
Diffstat (limited to 'script/core/diagnostics/undefined-field.lua')
-rw-r--r-- | script/core/diagnostics/undefined-field.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua index d4a0fe78..307182b3 100644 --- a/script/core/diagnostics/undefined-field.lua +++ b/script/core/diagnostics/undefined-field.lua @@ -21,11 +21,28 @@ return function (uri, callback) return src.type == 'getglobal' and src.special == '_G' end + local function canInfer2Class(src) + local className = vm.getClass(src, 0) + if not className then + local inferType = vm.getInferType(src, 0) + if inferType ~= 'any' and inferType ~= 'table' then + className = inferType + end + end + + return className and className ~= 'table' + end + local function checkUndefinedField(src) local fieldName = guide.getKeyName(src) if is_G(src)then return end + + if not canInfer2Class(src.node) then + return + end + local refs = vm.getFields(src.node, 0) local fields = {} |