diff options
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-class.lua | 46 | ||||
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-name.lua | 6 | ||||
-rw-r--r-- | script-beta/proto/define.lua | 1 | ||||
-rw-r--r-- | test-beta/diagnostics/init.lua | 1 |
4 files changed, 52 insertions, 2 deletions
diff --git a/script-beta/core/diagnostics/undefined-doc-class.lua b/script-beta/core/diagnostics/undefined-doc-class.lua new file mode 100644 index 00000000..bbfdceec --- /dev/null +++ b/script-beta/core/diagnostics/undefined-doc-class.lua @@ -0,0 +1,46 @@ +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 = {} + for _, doc in ipairs(state.ast.docs) do + if doc.type == 'doc.class' then + local ext = doc.extends + if not ext then + goto CONTINUE + end + local name = ext[1] + local docs = vm.getDocTypes(name) + if cache[name] == nil then + cache[name] = false + for _, otherDoc in ipairs(docs) do + if otherDoc.type == 'doc.class.name' then + cache[name] = true + break + end + end + end + if not cache[name] then + callback { + start = ext.start, + finish = ext.finish, + related = cache, + message = lang.script('DIAG_UNDEFINED_DOC_CLASS', name) + } + end + end + ::CONTINUE:: + end +end diff --git a/script-beta/core/diagnostics/undefined-doc-name.lua b/script-beta/core/diagnostics/undefined-doc-name.lua index bf885f6f..ba5e0a69 100644 --- a/script-beta/core/diagnostics/undefined-doc-name.lua +++ b/script-beta/core/diagnostics/undefined-doc-name.lua @@ -16,7 +16,11 @@ return function (uri, callback) local cache = {} guide.eachSource(state.ast.docs, function (source) - if source.type:sub(-5) ~= '.name' then + if source.type ~= 'doc.extends.name' + and source.type ~= 'doc.type.name' then + return + end + if source.parent.type == 'doc.class' then return end local name = source[1] diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index 5d737ce1..5aa8d82b 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-class'] = 'Warning', ['undefined-doc-name'] = 'Warning', ['circle-doc-class'] = 'Warning', } diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua index 649a6c9b..f8cfa39a 100644 --- a/test-beta/diagnostics/init.lua +++ b/test-beta/diagnostics/init.lua @@ -640,7 +640,6 @@ TEST [[ ---@class <!C : D!> ---@class <!D : A!> ]] -do return end TEST [[ ---@class A : B |