From 4ca61ec457822dd14966afa0752340ae8ce180a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 20 Nov 2020 21:57:09 +0800 Subject: no longer beta --- script/core/diagnostics/undefined-doc-param.lua | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 script/core/diagnostics/undefined-doc-param.lua (limited to 'script/core/diagnostics/undefined-doc-param.lua') diff --git a/script/core/diagnostics/undefined-doc-param.lua b/script/core/diagnostics/undefined-doc-param.lua new file mode 100644 index 00000000..af3e07bc --- /dev/null +++ b/script/core/diagnostics/undefined-doc-param.lua @@ -0,0 +1,52 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local define = require 'proto.define' +local vm = require 'vm' + +local function hasParamName(func, name) + if not func.args then + return false + end + for _, arg in ipairs(func.args) do + if arg[1] == name then + return true + end + end + return false +end + +return function (uri, callback) + local state = files.getAst(uri) + if not state then + return + end + + if not state.ast.docs then + return + end + + for _, doc in ipairs(state.ast.docs) do + if doc.type ~= 'doc.param' then + goto CONTINUE + end + local binds = doc.bindSources + if not binds then + goto CONTINUE + end + local param = doc.param + local name = param[1] + for _, source in ipairs(binds) do + if source.type == 'function' then + if not hasParamName(source, name) then + callback { + start = param.start, + finish = param.finish, + message = lang.script('DIAG_UNDEFINED_DOC_PARAM', name) + } + end + end + end + ::CONTINUE:: + end +end -- cgit v1.2.3