diff options
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-name.lua | 48 | ||||
-rw-r--r-- | test-beta/diagnostics/init.lua | 10 |
2 files changed, 39 insertions, 19 deletions
diff --git a/script-beta/core/diagnostics/undefined-doc-name.lua b/script-beta/core/diagnostics/undefined-doc-name.lua index ba5e0a69..07894a54 100644 --- a/script-beta/core/diagnostics/undefined-doc-name.lua +++ b/script-beta/core/diagnostics/undefined-doc-name.lua @@ -4,6 +4,27 @@ local lang = require 'language' local define = require 'proto.define' local vm = require 'vm' +local function hasNameOfClassOrAlias(name) + local docs = vm.getDocTypes(name) + for _, otherDoc in ipairs(docs) do + if otherDoc.type == 'doc.class.name' + or otherDoc.type == 'doc.alias.name' then + return true + end + end + return false +end + +local function hasNameOfGeneric(name, source) + if not source.typeGeneric then + return false + end + if not source.typeGeneric[name] then + return false + end + return true +end + return function (uri, callback) local state = files.getAst(uri) if not state then @@ -14,7 +35,6 @@ return function (uri, callback) return end - local cache = {} guide.eachSource(state.ast.docs, function (source) if source.type ~= 'doc.extends.name' and source.type ~= 'doc.type.name' then @@ -24,24 +44,14 @@ return function (uri, callback) 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) - } + if hasNameOfClassOrAlias(name) + or hasNameOfGeneric(name, source) then + return end + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_UNDEFINED_DOC_NAME', name) + } end) end diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua index eb79b7c1..4c21da69 100644 --- a/test-beta/diagnostics/init.lua +++ b/test-beta/diagnostics/init.lua @@ -738,3 +738,13 @@ TEST [[ ---@class c c = {} ]] + +TEST [[ +---@generic T: any +---@param v T +---@param message any +---@return T +function assert(v, message) + return v, message +end +]] |