From 28a21f6f3988c0bb2022748e8f8daae236d80f5c 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 16:01:55 +0800 Subject: =?UTF-8?q?=E8=AF=8A=E6=96=AD=E6=9C=AA=E5=AE=9A=E4=B9=89=E7=9A=84d?= =?UTF-8?q?ocname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/diagnostics/undefined-doc-name.lua | 43 ++++++++++++++++++++++ script-beta/proto/define.lua | 1 + 2 files changed, 44 insertions(+) create mode 100644 script-beta/core/diagnostics/undefined-doc-name.lua (limited to 'script-beta') diff --git a/script-beta/core/diagnostics/undefined-doc-name.lua b/script-beta/core/diagnostics/undefined-doc-name.lua new file mode 100644 index 00000000..bf885f6f --- /dev/null +++ b/script-beta/core/diagnostics/undefined-doc-name.lua @@ -0,0 +1,43 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local define = require 'proto.define' +local vm = require 'vm' + +return function (uri, callback) + local state = files.getAst(uri) + if not state then + return + end + + if not state.ast.docs then + return + end + + local cache = {} + guide.eachSource(state.ast.docs, function (source) + if source.type:sub(-5) ~= '.name' then + return + end + local name = source[1] + if cache[name] == nil then + cache[name] = false + local docs = vm.getDocTypes(name) + for _, otherDoc in ipairs(docs) do + if otherDoc.type == 'doc.class.name' + or otherDoc.type == 'doc.alias.name' then + cache[name] = true + break + end + end + end + if not cache[name] then + callback { + start = source.start, + finish = source.finish, + related = cache, + message = lang.script('DIAG_UNDEFINED_DOC_NAME', name) + } + end + end) +end diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index 119314fb..fdb38c6f 100644 --- a/script-beta/proto/define.lua +++ b/script-beta/proto/define.lua @@ -131,6 +131,7 @@ m.DiagnosticDefaultSeverity = { ['redundant-value'] = 'Hint', ['duplicate-doc-class'] = 'Warning', + ['undefined-doc-name'] = 'Warning', } --- 诊断报告标签 -- cgit v1.2.3