diff options
-rw-r--r-- | script/core/diagnostics/redefined-local.lua | 3 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-field.lua | 53 | ||||
-rw-r--r-- | script/core/diagnostics/unused-local.lua | 3 |
3 files changed, 33 insertions, 26 deletions
diff --git a/script/core/diagnostics/redefined-local.lua b/script/core/diagnostics/redefined-local.lua index 5e53d837..48093417 100644 --- a/script/core/diagnostics/redefined-local.lua +++ b/script/core/diagnostics/redefined-local.lua @@ -13,6 +13,9 @@ return function (uri, callback) or name == ast.ENVMode then return end + if source.tag == 'self' then + return + end local exist = guide.getLocal(source, name, source.start-1) if exist then callback { diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua index 6b2e718f..851e7c3d 100644 --- a/script/core/diagnostics/undefined-field.lua +++ b/script/core/diagnostics/undefined-field.lua @@ -87,35 +87,36 @@ return function (uri, callback) end local function checkUndefinedField(src) - local fieldName = guide.getKeyName(src) - - local allDocClass = getAllDocClassFromInfer(src.node) - if (not allDocClass) or (#allDocClass == 0) then - return - end - - local fields = getAllFieldsFromAllDocClass(allDocClass) - - -- 没找到任何 field,跳过检查 - if not fields then + if #vm.getDefs(src) > 0 then return end - - if not fields[fieldName] then - local message = lang.script('DIAG_UNDEF_FIELD', fieldName) - if src.type == 'getfield' and src.field then - callback { - start = src.field.start, - finish = src.field.finish, - message = message, - } - elseif src.type == 'getmethod' and src.method then - callback { - start = src.method.start, - finish = src.method.finish, - message = message, - } + local node = src.node + if node then + local defs = vm.getDefs(node) + local ok + for _, def in ipairs(defs) do + if def.type == 'doc.class.name' then + ok = true + break + end end + if not ok then + return + end + end + local message = lang.script('DIAG_UNDEF_FIELD', guide.getKeyName(src)) + if src.type == 'getfield' and src.field then + callback { + start = src.field.start, + finish = src.field.finish, + message = message, + } + elseif src.type == 'getmethod' and src.method then + callback { + start = src.method.start, + finish = src.method.finish, + message = message, + } end end guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField); diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua index 9bb2c492..1a77a45f 100644 --- a/script/core/diagnostics/unused-local.lua +++ b/script/core/diagnostics/unused-local.lua @@ -87,6 +87,9 @@ return function (uri, callback) or name == ast.ENVMode then return end + if source.tag == 'self' then + return + end if isToBeClosed(source) then return end |