summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/undefined-doc-param.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
commit4ca61ec457822dd14966afa0752340ae8ce180a1 (patch)
treeae8adb1ad82c717868e551e699fd3cf3bb290089 /script/core/diagnostics/undefined-doc-param.lua
parentc63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff)
downloadlua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip
no longer beta
Diffstat (limited to 'script/core/diagnostics/undefined-doc-param.lua')
-rw-r--r--script/core/diagnostics/undefined-doc-param.lua52
1 files changed, 52 insertions, 0 deletions
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