summaryrefslogtreecommitdiff
path: root/server/src/core/vm.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-23 16:43:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-23 16:43:23 +0800
commitc6f18e40500e5c1ffd5c27bc589d413804632cb3 (patch)
tree68d0d5137f47e6640e3290e92ddfffbf0a381b27 /server/src/core/vm.lua
parentcbcb02406fc0f317af5bd575515e9881e4bd5a25 (diff)
downloadlua-language-server-c6f18e40500e5c1ffd5c27bc589d413804632cb3.zip
支持全局变量的子项
Diffstat (limited to 'server/src/core/vm.lua')
-rw-r--r--server/src/core/vm.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index b69d928d..a851f859 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -391,6 +391,17 @@ function mt:getField(pValue, name, source)
return field
end
+function mt:isGlobal(field)
+ if field.type ~= 'field' then
+ return false
+ end
+ if field.parent.value.ENV then
+ return true
+ else
+ return false
+ end
+end
+
function mt:buildFunction(exp, object)
local func = self:createValue('function', exp)
func.args = {}
@@ -1281,9 +1292,20 @@ function mt:doSet(action)
if key.type == 'name' then
local var = self:getName(key[1], key)
self:setValue(var, value, key)
+ if self:isGlobal(var) then
+ self.results.globals[key[1]] = var
+ end
elseif key.type == 'simple' then
local field = self:getSimple(key, 'field')
self:setValue(field, value, key[#key])
+ local var = field
+ repeat
+ if self:isGlobal(var) then
+ self.results.globals[var.key] = var
+ break
+ end
+ var = var.parent
+ until not var
end
end)
end
@@ -1499,6 +1521,7 @@ local function compile(ast, lsp, uri)
sources= {},
strings= {},
indexs = {},
+ globals= {},
main = nil,
},
libraryValue = {},