diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-02-23 19:31:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-02-23 19:31:48 +0800 |
commit | 63396ada5c7d2037ec19ed45e99e1a56f23c590b (patch) | |
tree | 9a1beb761861b8628cd86715aee4a5040f6f3b3b /script/core | |
parent | 54876cb601466c409eb0be1af489c7ceca7f22cf (diff) | |
download | lua-language-server-63396ada5c7d2037ec19ed45e99e1a56f23c590b.zip |
close #328 new diagnostic: `no-implicit-any`
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/init.lua | 10 | ||||
-rw-r--r-- | script/core/diagnostics/no-implicit-any.lua | 32 |
2 files changed, 40 insertions, 2 deletions
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index bc3f3d8c..87afd4af 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -24,11 +24,17 @@ local function check(uri, name, results) local level = config.config.diagnostics.severity[name] or define.DiagnosticDefaultSeverity[name] - local neededFileStatus = config.config.diagnostics.neededFileStatus[name] - or define.DiagnosticDefaultNeededFileStatus[name] + local neededFileStatus = config.config.diagnostics.neededFileStatus[name] + or define.DiagnosticDefaultNeededFileStatus[name] + + if neededFileStatus == 'None' then + return + end + if neededFileStatus == 'Opened' and not files.isOpen(uri) then return end + local severity = define.DiagnosticSeverity[level] local clock = os.clock() require('core.diagnostics.' .. name)(uri, function (result) diff --git a/script/core/diagnostics/no-implicit-any.lua b/script/core/diagnostics/no-implicit-any.lua new file mode 100644 index 00000000..a2062b37 --- /dev/null +++ b/script/core/diagnostics/no-implicit-any.lua @@ -0,0 +1,32 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local define = require 'proto.define' +local vm = require 'vm' + +return function (uri, callback) + local ast = files.getAst(uri) + if not ast then + return + end + + guide.eachSource(ast.ast, function (source) + if source.type ~= 'local' + and source.type ~= 'setlocal' + and source.type ~= 'setglobal' + and source.type ~= 'getglobal' + and source.type ~= 'setfield' + and source.type ~= 'setindex' + and source.type ~= 'tablefield' + and source.type ~= 'tableindex' then + return + end + if vm.getInferType(source, 0) == 'any' then + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_IMPLICIT_ANY'), + } + end + end) +end |