diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-23 14:38:45 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-23 14:38:45 +0800 |
commit | ea19d0e46ea4828531ad481f6018d334cd0b5999 (patch) | |
tree | 642e5d2835e7319692106414b95298d1c25cf7b5 /server | |
parent | f41b764aa1b6ff6708da9ce84468839635e6720c (diff) | |
download | lua-language-server-ea19d0e46ea4828531ad481f6018d334cd0b5999.zip |
支持全局变量了
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/global.lua | 15 | ||||
-rw-r--r-- | server/src/service.lua | 5 | ||||
-rw-r--r-- | server/test/crossfile/definition.lua | 28 |
3 files changed, 33 insertions, 15 deletions
diff --git a/server/src/core/global.lua b/server/src/core/global.lua index 8aa801de..5704bfd4 100644 --- a/server/src/core/global.lua +++ b/server/src/core/global.lua @@ -26,6 +26,7 @@ end function mt:compileVM(uri, vm) self:clearGlobal(uri) + local seted = {} for k, v in next, vm.env.child do local get, set for _, info in ipairs(v) do @@ -37,10 +38,24 @@ function mt:compileVM(uri, vm) end if set then self:markSet(uri, k, v) + seted[#seted+1] = k elseif get then self:markGet(uri, k) end end + + local needReCompile = {} + for otherUri, gets in pairs(self.get) do + for _, key in ipairs(seted) do + if gets[key] ~= nil then + needReCompile[#needReCompile+1] = otherUri + goto CONTINUE + end + end + ::CONTINUE:: + end + + return needReCompile end function mt:getGlobal(key) diff --git a/server/src/service.lua b/server/src/service.lua index 84be9832..57606d19 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -264,7 +264,10 @@ function mt:_compileChain(obj, compiled) end function mt:_compileGlobal(obj, compiled) - self._global:compileVM(obj.uri, obj.vm) + local needReCompile = self._global:compileVM(obj.uri, obj.vm) + for _, uri in ipairs(needReCompile) do + self:needCompile(uri, compiled) + end end function mt:getGlobal(key) diff --git a/server/test/crossfile/definition.lua b/server/test/crossfile/definition.lua index 3fdd1854..d34d6868 100644 --- a/server/test/crossfile/definition.lua +++ b/server/test/crossfile/definition.lua @@ -183,17 +183,17 @@ TEST { } } ---TEST { --- { --- path = 'a.lua', --- content = [[ --- <!global!> = 1 --- ]], --- }, --- { --- path = 'b.lua', --- content = [[ --- print(<?global?>) --- ]], --- } ---} +TEST { + { + path = 'a.lua', + content = [[ + <!global!> = 1 + ]], + }, + { + path = 'b.lua', + content = [[ + print(<?global?>) + ]], + } +} |