diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-07 20:37:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-07 20:37:57 +0800 |
commit | c630729133d7109829962128ede29304a9b82ece (patch) | |
tree | a061035709e6636a2f424bd70f36547ba54c488a /script/core | |
parent | 3750bc297b35615510e9f3f0c3a850baf78a44dc (diff) | |
download | lua-language-server-c630729133d7109829962128ede29304a9b82ece.zip |
update
Diffstat (limited to 'script/core')
-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 |