From d42b1d9427b186470ff571b67cf0d1397c3f30cd 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, 23 Oct 2020 17:37:58 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/diagnostics/doc-field-no-class.lua | 42 +++++++++++++++++ .../core/diagnostics/duplicate-doc-param.lua | 37 +++++++++++++++ .../core/diagnostics/undefined-doc-param.lua | 52 ++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 script-beta/core/diagnostics/doc-field-no-class.lua create mode 100644 script-beta/core/diagnostics/duplicate-doc-param.lua create mode 100644 script-beta/core/diagnostics/undefined-doc-param.lua (limited to 'script-beta/core/diagnostics') diff --git a/script-beta/core/diagnostics/doc-field-no-class.lua b/script-beta/core/diagnostics/doc-field-no-class.lua new file mode 100644 index 00000000..88c61824 --- /dev/null +++ b/script-beta/core/diagnostics/doc-field-no-class.lua @@ -0,0 +1,42 @@ +local files = require 'files' +local lang = require 'language' + +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.field' then + goto CONTINUE + end + local bindGroup = doc.bindGroup + if not bindGroup then + goto CONTINUE + end + local ok + for _, other in ipairs(bindGroup) do + if other.type == 'doc.class' then + ok = true + elseif other == doc then + if not ok then + callback { + start = doc.start, + finish = doc.finish, + message = lang.script('DIAG_DOC_FIELD_NO_CLASS'), + } + end + goto CONTINUE + elseif other.type == 'doc.field' then + else + ok = false + end + end + ::CONTINUE:: + end +end diff --git a/script-beta/core/diagnostics/duplicate-doc-param.lua b/script-beta/core/diagnostics/duplicate-doc-param.lua new file mode 100644 index 00000000..676a6fb4 --- /dev/null +++ b/script-beta/core/diagnostics/duplicate-doc-param.lua @@ -0,0 +1,37 @@ +local files = require 'files' +local lang = require 'language' + +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 name = doc.param[1] + local bindGroup = doc.bindGroup + if not bindGroup then + goto CONTINUE + end + for _, other in ipairs(bindGroup) do + if other ~= doc + and other.type == 'doc.param' + and other.param[1] == name then + callback { + start = doc.param.start, + finish = doc.param.finish, + message = lang.script('DIAG_DUPLICATE_DOC_PARAM', name) + } + goto CONTINUE + end + end + ::CONTINUE:: + end +end diff --git a/script-beta/core/diagnostics/undefined-doc-param.lua b/script-beta/core/diagnostics/undefined-doc-param.lua new file mode 100644 index 00000000..af3e07bc --- /dev/null +++ b/script-beta/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