summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/diagnostics/doc-field-no-class.lua42
-rw-r--r--script-beta/core/diagnostics/duplicate-doc-param.lua37
-rw-r--r--script-beta/core/diagnostics/undefined-doc-param.lua52
-rw-r--r--script-beta/language.lua3
-rw-r--r--script-beta/parser/luadoc.lua9
-rw-r--r--script-beta/proto/define.lua3
6 files changed, 142 insertions, 4 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
diff --git a/script-beta/language.lua b/script-beta/language.lua
index d1a4b4cf..6077e4c6 100644
--- a/script-beta/language.lua
+++ b/script-beta/language.lua
@@ -101,6 +101,9 @@ local function loadLang(name, language)
end,
__call = function (self, key, ...)
local str = self[key]
+ if not ... then
+ return str
+ end
local suc, res
if type(...) == 'table' then
suc, res = pcall(formatAsTable, str, ...)
diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua
index 88521a8b..9c9ea113 100644
--- a/script-beta/parser/luadoc.lua
+++ b/script-beta/parser/luadoc.lua
@@ -686,16 +686,17 @@ local function bindDoc(state, lns, binded)
if not lastDoc then
return
end
+ local bindSources = {}
+ for _, doc in ipairs(binded) do
+ doc.bindGroup = binded
+ doc.bindSources = bindSources
+ end
local row = guide.positionOf(lns, lastDoc.start)
local start, finish = guide.lineRange(lns, row + 1)
if start >= finish then
-- 空行
return
end
- local bindSources = {}
- for _, doc in ipairs(binded) do
- doc.bindSources = bindSources
- end
guide.eachSourceBetween(state.ast, start, finish, function (src)
if src.type == 'local'
or src.type == 'setlocal'
diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua
index 5aa8d82b..f69660cf 100644
--- a/script-beta/proto/define.lua
+++ b/script-beta/proto/define.lua
@@ -134,6 +134,9 @@ m.DiagnosticDefaultSeverity = {
['undefined-doc-class'] = 'Warning',
['undefined-doc-name'] = 'Warning',
['circle-doc-class'] = 'Warning',
+ ['undefined-doc-param'] = 'Warning',
+ ['duplicate-doc-param'] = 'Warning',
+ ['doc-field-no-class'] = 'Warning',
}
--- 诊断报告标签