diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-11 16:52:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-11 16:52:51 +0800 |
commit | 3f2c19d1990d858989d9c908964b93f99789f0e4 (patch) | |
tree | db5f805e32d3e5a0cae84544a09bf8494a864482 /script-beta/core/diagnostics/undefined-doc-name.lua | |
parent | 16ed5b65e4b52933942b947fb9a5ddfd5513c3f1 (diff) | |
download | lua-language-server-3f2c19d1990d858989d9c908964b93f99789f0e4.zip |
修正泛型的一个诊断问题
Diffstat (limited to 'script-beta/core/diagnostics/undefined-doc-name.lua')
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-name.lua | 48 |
1 files changed, 29 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 |