summaryrefslogtreecommitdiff
path: root/server/src/matcher/vm.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-20 16:53:59 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-20 16:53:59 +0800
commit0f8123a8a45db5c568149e03876d4f3c57dacc52 (patch)
treeff2bf32ad3e588d79d937be9cc209e0a8993563f /server/src/matcher/vm.lua
parent99fbc125e4c91ee2f96c6bcca9d6c166e4e98f9c (diff)
downloadlua-language-server-0f8123a8a45db5c568149e03876d4f3c57dacc52.zip
合并其他文件的返回值
Diffstat (limited to 'server/src/matcher/vm.lua')
-rw-r--r--server/src/matcher/vm.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index c9fe1fd0..05b4f2e6 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -35,6 +35,24 @@ local function orderTable()
})
end
+local function deepCopy(t, mark, new)
+ mark = mark or {}
+ new = new or {}
+ for k, v in pairs(t) do
+ if type(v) == 'table' then
+ if mark[v] then
+ new[k] = mark[v]
+ else
+ mark[v] = {}
+ new[k] = deepCopy(v, mark, mark[v])
+ end
+ else
+ new[k] = v
+ end
+ end
+ return new
+end
+
local mt = {}
mt.__index = mt
@@ -1157,6 +1175,19 @@ function mt:createEnvironment()
gValue.child = envValue.child
end
+function mt:mergeRequire(value, destVM)
+ -- 取出对方的主函数
+ local main = destVM.results.main
+ -- 获取主函数返回值,注意不能修改对方的环境
+ local mainValue
+ if not main.returns then
+ mainValue = self:createValue('nil')
+ else
+ mainValue = deepCopy(main.returns[1])
+ end
+ self:mergeValue(value, mainValue)
+end
+
function mt:loadRequires()
if not self.lsp or not self.lsp.workspace then
return
@@ -1168,6 +1199,7 @@ function mt:loadRequires()
-- 如果循环require,这里会返回nil
local destVM = self.lsp:loadVM(uri)
if destVM then
+ self:mergeRequire(req.value, destVM)
end
end
end