summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/core/global.lua21
-rw-r--r--server/src/core/vm.lua23
-rw-r--r--server/test/crossfile/definition.lua15
3 files changed, 45 insertions, 14 deletions
diff --git a/server/src/core/global.lua b/server/src/core/global.lua
index ba4fdc47..9dca50d0 100644
--- a/server/src/core/global.lua
+++ b/server/src/core/global.lua
@@ -26,26 +26,19 @@ end
function mt:compileVM(uri, vm)
local seted = {}
- for k, v in next, vm.env.child do
- local get, set
- for _, info in ipairs(v) do
- if info.type == 'get' then
- get = true
- elseif info.type == 'set' then
- set = true
- end
- end
- if set then
- self:markSet(uri, k, v)
- seted[#seted+1] = k
- elseif get then
+ for k, v in pairs(vm.results.globals) do
+ seted[k] = true
+ self:markSet(uri, k, v)
+ end
+ for k in next, vm.env.child do
+ if not seted[k] then
self:markGet(uri, k)
end
end
local needReCompile = {}
for otherUri, gets in pairs(self.get) do
- for _, key in ipairs(seted) do
+ for key in pairs(seted) do
if gets[key] ~= nil then
needReCompile[#needReCompile+1] = otherUri
goto CONTINUE
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 = {},
diff --git a/server/test/crossfile/definition.lua b/server/test/crossfile/definition.lua
index 6ff0cf32..396f54c5 100644
--- a/server/test/crossfile/definition.lua
+++ b/server/test/crossfile/definition.lua
@@ -212,3 +212,18 @@ TEST {
]],
},
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ x.<!global!> = 1
+ ]],
+ },
+ {
+ path = 'b.lua',
+ content = [[
+ print(x.<?global?>)
+ ]],
+ }
+}