summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/infer.lua29
-rw-r--r--test/hover/init.lua16
2 files changed, 38 insertions, 7 deletions
diff --git a/script/core/infer.lua b/script/core/infer.lua
index c4af5122..4feba41c 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -609,19 +609,34 @@ function m.isTrue(source, mark)
if not source then
return false
end
- local literals = m.searchLiterals(source, nil, mark)
- for literal in pairs(literals) do
- if literal ~= false then
- return true
+ mark = mark or {}
+ if not mark.isTrue then
+ mark.isTrue = {}
+ end
+ if mark.isTrue[source] == nil then
+ local literals = m.searchLiterals(source, nil, mark)
+ for literal in pairs(literals) do
+ if literal ~= false then
+ mark.isTrue[source] = true
+ break
+ end
end
+ mark.isTrue[source] = false
end
- return false
+ return mark.isTrue[source]
end
---判断对象的推断类型是否包含某个类型
function m.hasType(source, tp, mark)
- local infers = m.searchInfers(source, nil, mark)
- return infers[tp] or false
+ mark = mark or {}
+ if not mark.hasType then
+ mark.hasType = {}
+ end
+ if mark.hasType[source] == nil then
+ local infers = m.searchInfers(source, nil, mark)
+ mark.hasType[source] = infers[tp] or false
+ end
+ return mark.hasType[source]
end
---搜索并显示推断类型
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 79469b90..9a30ab81 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -1613,3 +1613,19 @@ local t: {
z: boolean,
}
]]
+
+TEST [[
+<?a?>.b = 10 * 60
+]]
+[[
+global a: {
+ b: integer,
+}
+]]
+
+TEST [[
+a.<?b?> = 10 * 60
+]]
+[[
+global a.b: integer
+]]