summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-29 13:46:28 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-29 13:46:28 +0800
commitcc33507654fa35640118b13bdd3f19696631980a (patch)
tree636cad7ea765a4439d9655dcf9cba39f3f68e17c /server
parent9c2843279fb04b75169057c3d81a93ce87ebcf34 (diff)
downloadlua-language-server-cc33507654fa35640118b13bdd3f19696631980a.zip
尽量不合并value
Diffstat (limited to 'server')
-rw-r--r--server/src/core/definition.lua2
-rw-r--r--server/src/vm/local.lua8
-rw-r--r--server/src/vm/value.lua20
-rw-r--r--server/src/vm/vm.lua5
-rw-r--r--server/test/diagnostics/init.lua8
5 files changed, 37 insertions, 6 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index b348a386..e41c6727 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -105,7 +105,7 @@ local function parseLocal(vm, source, lsp)
return positions
end
local value = source:bindValue()
- if value.uri ~= '' and value.uri ~= vm.uri then
+ if value and value.uri ~= '' and value.uri ~= vm.uri then
return parseValueCrossFile(vm, source, lsp)
end
positions[#positions+1] = {
diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua
index b8a387fe..0da5112f 100644
--- a/server/src/vm/local.lua
+++ b/server/src/vm/local.lua
@@ -9,11 +9,17 @@ mt.type = 'local'
mt._close = math.maxinteger
function mt:setValue(value)
+ if not value then
+ return
+ end
if self.value then
- self.value:mergeValue(value)
+ --self.value:mergeValue(value)
+ self.value:mergeType(value)
+ self.value = value
else
self.value = value
end
+ return value
end
function mt:getValue()
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index 35f92b5d..872e96b6 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -96,8 +96,9 @@ function mt:rawSet(index, value, source)
self._child = {}
end
if self._child[index] then
- self._child[index]:mergeValue(value)
- --self._child[index] = value
+ --self._child[index]:mergeValue(value)
+ self._child[index]:mergeType(value)
+ self._child[index] = value
else
self._child[index] = value
end
@@ -262,6 +263,21 @@ function mt:eachChild(callback, mark, foundIndex)
return method:eachChild(callback, mark, foundIndex)
end
+function mt:mergeType(value)
+ if self == value then
+ return
+ end
+ if not value then
+ return
+ end
+ if value._type then
+ for tp, rate in pairs(value._type) do
+ self:setType(tp, rate)
+ end
+ end
+ value._type = self._type
+end
+
function mt:mergeValue(value)
if self == value then
return
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 3b52e1f0..5d6b024f 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -941,6 +941,7 @@ function mt:doLocalFunction(action)
local func = self:buildFunction(action)
func:addInfo('local', name)
loc:setValue(func)
+ name:bindValue(func, 'local')
end
end
end
@@ -1098,13 +1099,13 @@ function mt:createLocal(key, source, value)
end
if not value then
- value = valueMgr.create('nil', self:getDefaultSource())
+ value = self:createValue('nil', source)
end
loc = localMgr.create(key, source, value)
self:saveLocal(key, loc)
self:bindLocal(source, loc, 'local')
- value:addInfo('local', source or self:getDefaultSource())
+ value:addInfo('local', source)
return loc
end
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index 4af8f975..c9a8a95d 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -222,3 +222,11 @@ TEST [[
next({}, 1, <!2!>)
print(1, 2, 3, 4, 5)
]]
+
+TEST [[
+local realTostring = tostring
+tostring = function () end
+tostring(<!1!>)
+tostring = realTostring
+tostring(1)
+]]