diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-12 15:32:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-12 15:32:13 +0800 |
commit | 877540a64b8a2cbf51f8b67f9f31d397957f3654 (patch) | |
tree | d548cc06fa64fbb956ad9f3d180cf3338253e032 /server | |
parent | 095984fc21264c4c13f785ef833d4711034dc28f (diff) | |
download | lua-language-server-877540a64b8a2cbf51f8b67f9f31d397957f3654.zip |
修改全局变量策略
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/global.lua | 9 | ||||
-rw-r--r-- | server/src/service.lua | 16 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 8 |
3 files changed, 21 insertions, 12 deletions
diff --git a/server/src/core/global.lua b/server/src/core/global.lua index 7be76818..007f0fd9 100644 --- a/server/src/core/global.lua +++ b/server/src/core/global.lua @@ -24,11 +24,6 @@ end function mt:clearGlobal(uri) self.set[uri] = nil self.get[uri] = nil - local globalValue = self.lsp.globalValue - if not globalValue then - return - end - globalValue:removeUri(uri) end function mt:getAllUris() @@ -44,6 +39,10 @@ function mt:getAllUris() return uris end +function mt:hasSetGlobal(uri) + return self.set[uri] ~= nil +end + return function (lsp) return setmetatable({ get = {}, diff --git a/server/src/service.lua b/server/src/service.lua index 4141b172..0c533b35 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -296,12 +296,12 @@ function mt:_compileGlobal(compiled) end end -function mt:_clearGlobal(uri, compiled) +function mt:_clearGlobal(uri) self.global:clearGlobal(uri) - local uris = self.global:getAllUris() - for _, uri in ipairs(uris) do - self:needCompile(uri, compiled) - end +end + +function mt:_hasSetGlobal(uri) + return self.global:hasSetGlobal(uri) end function mt:compileVM(uri) @@ -320,7 +320,7 @@ function mt:compileVM(uri) local version = obj.version obj.astCost = os.clock() - clock self:_clearChainNode(obj, uri) - --self:_clearGlobal(uri, compiled) + self:_clearGlobal(uri) local clock = os.clock() local vm = buildVM(ast, self, uri) @@ -350,7 +350,9 @@ function mt:compileVM(uri) end self:_compileChain(obj, compiled) - --self:_compileGlobal(compiled) + if self:_hasSetGlobal(uri) then + self:_compileGlobal(compiled) + end return obj end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index a5c9168d..f78f2690 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -365,6 +365,11 @@ function mt:getName(name, source) source:bindValue(global, 'get') source:set('global', true) source:set('parent', ENVValue) + if not global:getLib() then + if self.lsp then + self.lsp.global:markGet(self:getUri()) + end + end return global end @@ -387,6 +392,9 @@ function mt:setName(name, source, value) ENVValue:setChild(name, value) source:set('global', true) source:set('parentValue', ENVValue) + if self.lsp then + self.lsp.global:markSet(self:getUri()) + end end function mt:getIndex(source) |