diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-19 15:21:23 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-19 15:21:23 +0800 |
commit | 9044f63d2e244cf01301aa6af2e62faea0e91e59 (patch) | |
tree | 2e709acfd34c56989120912fc001c9e6d28f913b /server | |
parent | 4087a9774bbfbad2652725684b812ed1eca43bde (diff) | |
download | lua-language-server-9044f63d2e244cf01301aa6af2e62faea0e91e59.zip |
优化
Diffstat (limited to 'server')
-rw-r--r-- | server/src/vm/value.lua | 16 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 7 |
2 files changed, 17 insertions, 6 deletions
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 7ac70181..c9d8cb4b 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -40,6 +40,10 @@ local function create (tp, source, literal) end local function isDeadChild(value, index) + -- 非全局值不会出现dead child + if not value._global then + return false + end for srcId, info in pairs(value._info) do local src = sourceMgr.list[srcId] if src @@ -310,15 +314,19 @@ function mt:addInfo(tp, source, ...) self._info[id] = info self._infoCount = self._infoCount + 1 - if self._infoCount > self._infoLimit then + -- 只有全局值需要压缩info + if self._global and self._infoCount > self._infoLimit then + local count = 0 for srcId in pairs(self._info) do local src = sourceMgr.list[srcId] - if not src then + if src then + count = count + 1 + else self._info[srcId] = nil - self._infoCount = self._infoCount - 1 end end - self._infoLimit = self._infoCount * 2 + self._infoCount = count + self._infoLimit = count * 2 if self._infoLimit < 10 then self._infoLimit = 10 end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 250863a8..edf70c30 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -156,9 +156,11 @@ end function mt:getRequire(strValue, destVM) -- 取出对方的主函数 local main = destVM.main - -- 获取主函数返回值,注意不能修改对方的环境 + -- 获取主函数返回值 local mainValue = main:getFunction():getReturn(1) - if not mainValue then + if mainValue then + mainValue:markGlobal() + else mainValue = self:createValue('any', self:getDefaultSource()) mainValue.uri = destVM.uri end @@ -171,6 +173,7 @@ function mt:getLoadFile(strValue, destVM) local main = destVM.main -- loadfile 的返回值就是对方的主函数 local mainValue = main + mainValue:markGlobal() return mainValue end |