diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-08-11 19:40:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-08-11 19:40:52 +0800 |
commit | 525d095c55c696a36f67caae5e4e8f631e10c116 (patch) | |
tree | c3475e08b037efdbbe2562f3a5c1086889056573 /script/core | |
parent | 1055a8547668308633601a8b67f1a0b52075de3f (diff) | |
download | lua-language-server-525d095c55c696a36f67caae5e4e8f631e10c116.zip |
stash
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/inject-field.lua | 54 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-field.lua | 8 |
2 files changed, 54 insertions, 8 deletions
diff --git a/script/core/diagnostics/inject-field.lua b/script/core/diagnostics/inject-field.lua new file mode 100644 index 00000000..62e1d1ca --- /dev/null +++ b/script/core/diagnostics/inject-field.lua @@ -0,0 +1,54 @@ +local files = require 'files' +local vm = require 'vm' +local lang = require 'language' +local guide = require 'parser.guide' +local await = require 'await' + +local skipCheckClass = { + ['unknown'] = true, + ['any'] = true, + ['table'] = true, +} + +---@async +return function (uri, callback) + local ast = files.getState(uri) + if not ast then + return + end + + ---@async + local function checkInjectField(src) + await.delay() + + local node = src.node + if node then + local ok + for view in vm.getInfer(node):eachView(uri) do + if skipCheckClass[view] then + return + end + ok = true + end + if not ok then + return + end + end + local message = lang.script('DIAG_INJECT_FIELD', guide.getKeyName(src)) + if src.type == 'setfield' and src.field then + callback { + start = src.field.start, + finish = src.field.finish, + message = message, + } + elseif src.type == 'setfield' and src.method then + callback { + start = src.method.start, + finish = src.method.finish, + message = message, + } + end + end + guide.eachSourceType(ast.ast, 'setfield', checkInjectField) + guide.eachSourceType(ast.ast, 'setmethod', checkInjectField) +end diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua index a83241f5..4fd55966 100644 --- a/script/core/diagnostics/undefined-field.lua +++ b/script/core/diagnostics/undefined-field.lua @@ -8,13 +8,6 @@ local skipCheckClass = { ['unknown'] = true, ['any'] = true, ['table'] = true, - ['nil'] = true, - ['number'] = true, - ['integer'] = true, - ['boolean'] = true, - ['function'] = true, - ['userdata'] = true, - ['lightuserdata'] = true, } ---@async @@ -61,5 +54,4 @@ return function (uri, callback) end guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField) guide.eachSourceType(ast.ast, 'getmethod', checkUndefinedField) - guide.eachSourceType(ast.ast, 'getindex', checkUndefinedField) end |