summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-05 10:35:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-05 10:35:02 +0800
commit5b95f9f1ec40ade76e55007e5cde73c0ffa96d26 (patch)
tree282b060f0e1797e8057571102b432561f2a7d2ad
parent88b58826a4e84d5bc4c0cf99e544c5b4073cb198 (diff)
downloadlua-language-server-5b95f9f1ec40ade76e55007e5cde73c0ffa96d26.zip
kick doc.generic on cleaning
-rw-r--r--script/parser/guide.lua21
-rw-r--r--test/completion/init.lua16
2 files changed, 29 insertions, 8 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 19e60a0e..7fa2f3e2 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -2695,7 +2695,6 @@ function m.viewInferType(infers)
local mark = {}
local types = {}
local hasDoc
- local generic
for i = 1, #infers do
local infer = infers[i]
local src = infer.source
@@ -2704,10 +2703,7 @@ function m.viewInferType(infers)
or src.type == 'doc.type.name'
or src.type == 'doc.type.array'
or src.type == 'doc.type.generic' then
- if src.typeGeneric then
- generic = infer
- end
- if infer.type ~= 'any' and not src.typeGeneric then
+ if infer.type ~= 'any' then
hasDoc = true
break
end
@@ -2745,9 +2741,6 @@ function m.viewInferType(infers)
::CONTINUE::
end
end
- if #types == 0 and generic then
- types[#types+1] = generic.type
- end
return m.mergeTypes(types)
end
@@ -3868,6 +3861,7 @@ function m.inferByPCallReturn(status, source)
end
function m.cleanInfers(infers, obj)
+ -- kick lower level infers
local level = 0
if obj.type ~= 'select' then
for i = 1, #infers do
@@ -3877,6 +3871,7 @@ function m.cleanInfers(infers, obj)
end
end
end
+ -- merge infers
local mark = {}
for i = #infers, 1, -1 do
local infer = infers[i]
@@ -3894,6 +3889,16 @@ function m.cleanInfers(infers, obj)
end
::CONTINUE::
end
+ -- kick doc.generic
+ if #infers > 1 then
+ for i = #infers, 1, -1 do
+ local infer = infers[i]
+ if infer.source.typeGeneric then
+ infers[i] = infers[#infers]
+ infers[#infers] = nil
+ end
+ end
+ end
end
function m.searchInfer(status, obj)
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 37e7c255..7a797df9 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -1900,3 +1900,19 @@ local s
s.$
]]
(EXISTS)
+
+TEST [[
+---@class C
+local t
+
+local vvv = assert(t)
+vvv$
+]]
+{
+ {
+ label = 'vvv',
+ detail = 'C',
+ kind = define.CompletionItemKind.Variable,
+ description = EXISTS,
+ },
+}