summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-11 16:52:51 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-11 16:52:51 +0800
commit3f2c19d1990d858989d9c908964b93f99789f0e4 (patch)
treedb5f805e32d3e5a0cae84544a09bf8494a864482
parent16ed5b65e4b52933942b947fb9a5ddfd5513c3f1 (diff)
downloadlua-language-server-3f2c19d1990d858989d9c908964b93f99789f0e4.zip
修正泛型的一个诊断问题
-rw-r--r--script-beta/core/diagnostics/undefined-doc-name.lua48
-rw-r--r--test-beta/diagnostics/init.lua10
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
+]]