summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-30 09:35:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-30 09:35:11 +0800
commit4f0379c5cadd79df2e5bc593198b5464aeeb982e (patch)
tree0aa88eaf3f7909edd7a0da109bf51d5eef7dc86d
parent4429b76d8fe63c5f540478e7e9f123996d6da049 (diff)
downloadlua-language-server-4f0379c5cadd79df2e5bc593198b5464aeeb982e.zip
修改一些推断
-rw-r--r--server/src/core/value.lua2
-rw-r--r--server/src/core/vm.lua12
2 files changed, 12 insertions, 2 deletions
diff --git a/server/src/core/value.lua b/server/src/core/value.lua
index 05248d0d..a998d195 100644
--- a/server/src/core/value.lua
+++ b/server/src/core/value.lua
@@ -19,7 +19,7 @@ function mt:inference(tp, rate)
if not tp then
tp = 'nil'
end
- if tp == 'any' then
+ if tp == 'any' or tp == 'nil' then
rate = 0.0
end
if not self._type then
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index b88ae1ab..0a2a773c 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -919,13 +919,15 @@ function mt:getSimple(simple, mode)
local obj = simple[i]
local tp = obj.type
obj.uri = self.uri
+ value = self:selectList(value, 1)
if tp == 'call' then
+ value:inference('function', 0.9)
local args = self:unpackList(obj)
if object then
table.insert(args, 1, self:getValue(object))
end
- local func = self:selectList(value, 1)
+ local func = value
-- 函数的返回值一定是list
value = self:call(func, args, obj)
if i < #simple then
@@ -939,6 +941,8 @@ function mt:getSimple(simple, mode)
}
parentName = parentName .. '(...)'
elseif tp == 'index' then
+ value:inference('table', 0.8)
+ value:inference('string', 0.2)
local child = obj[1]
obj.indexName = parentName
local index = self:getIndex(child)
@@ -961,6 +965,8 @@ function mt:getSimple(simple, mode)
parentName = ('%s[?]'):format(parentName)
end
elseif tp == 'name' then
+ value:inference('table', 0.8)
+ value:inference('string', 0.2)
if mode == 'value' or i < #simple then
field = self:getField(value, obj[1], obj) or self:createField(value, obj[1], obj)
field.parentValue = value
@@ -977,10 +983,14 @@ function mt:getSimple(simple, mode)
obj.parentName = parentName
parentName = parentName .. '.' .. field.key
elseif tp == ':' then
+ value:inference('table', 0.8)
+ value:inference('string', 0.2)
object = field
simple[i-1].colon = obj
colon = colon
elseif tp == '.' then
+ value:inference('table', 0.8)
+ value:inference('string', 0.2)
simple[i-1].dot = obj
end
end