summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-16 21:20:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-16 21:20:52 +0800
commit755ecb36a18ed32d2409597441e590f68774e7d8 (patch)
treeb187fd8ee6e80c2acc135ba1c9730b603007ee3a
parentfbac27b0a2ffd7ee82c37f70bde7f69ba2e2cdae (diff)
downloadlua-language-server-755ecb36a18ed32d2409597441e590f68774e7d8.zip
修改infer
-rw-r--r--script-beta/parser/guide.lua35
-rw-r--r--test-beta/type_inference/init.lua2
2 files changed, 27 insertions, 10 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 925ee9ab..06e6949c 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -3725,18 +3725,35 @@ function m.inferByPCallReturn(status, source)
end
function m.cleanInfers(infers)
- local mark = {}
+ local hasDoc
for i = 1, #infers do
local infer = infers[i]
- if not infer then
- return
+ if infer.source.type == 'doc.class'
+ or infer.source.type == 'doc.type.name' then
+ hasDoc = true
end
- local key = ('%s|%p'):format(infer.type, infer.source)
- if mark[key] then
- infers[i] = infers[#infers]
- infers[#infers] = nil
- else
- mark[key] = true
+ end
+ if hasDoc then
+ for i = #infers, 1, -1 do
+ local infer = infers[i]
+ if infer.source.type == 'doc.class'
+ or infer.source.type == 'doc.type.name' then
+ else
+ infers[i] = infers[#infers]
+ infers[#infers] = nil
+ end
+ end
+ else
+ local mark = {}
+ for i = #infers, 1, -1 do
+ local infer = infers[i]
+ local key = ('%s|%p'):format(infer.type, infer.source)
+ if mark[key] then
+ infers[i] = infers[#infers]
+ infers[#infers] = nil
+ else
+ mark[key] = true
+ end
end
end
end
diff --git a/test-beta/type_inference/init.lua b/test-beta/type_inference/init.lua
index 4998ee79..edbe0fe2 100644
--- a/test-beta/type_inference/init.lua
+++ b/test-beta/type_inference/init.lua
@@ -200,7 +200,7 @@ end
_, <?y?> = pcall(x)
]]
-TEST 'table' [[
+TEST 'os' [[
local <?os?> = require 'os'
]]