diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-23 17:37:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-23 17:37:58 +0800 |
commit | d42b1d9427b186470ff571b67cf0d1397c3f30cd (patch) | |
tree | 369090cc2d5d3306b4490c7ffc9828c83fbaf7c3 /script-beta/core/diagnostics | |
parent | db2b91b69613f682031459721e2c6f5d710571a6 (diff) | |
download | lua-language-server-d42b1d9427b186470ff571b67cf0d1397c3f30cd.zip |
更新诊断
Diffstat (limited to 'script-beta/core/diagnostics')
-rw-r--r-- | script-beta/core/diagnostics/doc-field-no-class.lua | 42 | ||||
-rw-r--r-- | script-beta/core/diagnostics/duplicate-doc-param.lua | 37 | ||||
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-param.lua | 52 |
3 files changed, 131 insertions, 0 deletions
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 |