diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-13 14:46:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-13 14:46:52 +0800 |
commit | 6300e191ee1a36b79e70bf572614d4638df1c4c8 (patch) | |
tree | e4f5c374ec16a83cd6f2647269d72d491ea0c1d1 /server/src/vm/vm.lua | |
parent | a546d8a79f795415cf5875fe58483b9bd9ea9d3b (diff) | |
download | lua-language-server-6300e191ee1a36b79e70bf572614d4638df1c4c8.zip |
一处清理
Diffstat (limited to 'server/src/vm/vm.lua')
-rw-r--r-- | server/src/vm/vm.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 4a54aeae..00fce559 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -8,6 +8,8 @@ local buildGlobal = require 'vm.global' local createMulti = require 'vm.multi' local libraryBuilder = require 'vm.library' +local CachedSource = setmetatable({}, { __mode = 'kv' }) + local mt = {} mt.__index = mt @@ -1075,6 +1077,7 @@ function mt:instantSource(source) if instantSource(self, source) then source:setUri(self:getUri()) self.sources[#self.sources+1] = source + CachedSource[source] = true end return source end @@ -1142,7 +1145,13 @@ function mt:isRemoved() end function mt:remove() + if self._removed then + return + end self._removed = true + for _, source in ipairs(self.sources) do + source._dead = true + end end local function compile(ast, lsp, uri) @@ -1174,5 +1183,14 @@ return function (ast, lsp, uri) if not suc then return nil, res end + local total = 0 + local alive = 0 + for source in pairs(CachedSource) do + if not source:isDead() then + alive = alive + 1 + end + total = total + 1 + end + log.debug(('CachedSource: %d/%d'):format(alive, total)) return res end |