diff options
-rw-r--r-- | script/core/diagnostics/unknown-diag-code.lua | 31 | ||||
-rw-r--r-- | script/proto/define.lua | 2 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 4 |
3 files changed, 37 insertions, 0 deletions
diff --git a/script/core/diagnostics/unknown-diag-code.lua b/script/core/diagnostics/unknown-diag-code.lua new file mode 100644 index 00000000..45d3b6db --- /dev/null +++ b/script/core/diagnostics/unknown-diag-code.lua @@ -0,0 +1,31 @@ +local files = require 'files' +local lang = require 'language' +local define = require 'proto.define' + +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.diagnostic' then + if doc.names then + for _, nameUnit in ipairs(doc.names) do + local code = nameUnit[1] + if not define.DiagnosticDefaultSeverity[code] then + callback { + start = nameUnit.start, + finish = nameUnit.finish, + message = lang.script.DIAG_UNKNOWN_DIAG_CODE, + } + end + end + end + end + end +end diff --git a/script/proto/define.lua b/script/proto/define.lua index 3df97520..6ba02dd3 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -85,6 +85,7 @@ m.DiagnosticDefaultSeverity = { ['duplicate-doc-param'] = 'Warning', ['doc-field-no-class'] = 'Warning', ['duplicate-doc-field'] = 'Warning', + ['unknown-diag-code'] = 'Waiting', } ---@alias DiagnosticDefaultNeededFileStatus @@ -134,6 +135,7 @@ m.DiagnosticDefaultNeededFileStatus = { ['duplicate-doc-param'] = 'Any', ['doc-field-no-class'] = 'Any', ['duplicate-doc-field'] = 'Any', + ['unknown-diag-code'] = 'Any', } --- 诊断报告标签 diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 0ee558af..6f250543 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -1095,3 +1095,7 @@ TEST [[ ---@diagnostic enable x = 1 ]] + +TEST [[ +---@diagnostic disable-next-line: <!xxx!> +]] |