summaryrefslogtreecommitdiff
path: root/server/src/emmy/manager.lua
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-18 11:42:45 +0800
committersumneko <sumneko@hotmail.com>2019-04-18 11:42:45 +0800
commit04c3ce15f1515b11e43e4630888e323c6372b409 (patch)
treecfd2659fdaac0499416f8bf1406641f35edd6cb2 /server/src/emmy/manager.lua
parent1c0416baecc6db9720beb18d5abfc3b7ef33ffbe (diff)
downloadlua-language-server-04c3ce15f1515b11e43e4630888e323c6372b409.zip
emmy.class
Diffstat (limited to 'server/src/emmy/manager.lua')
-rw-r--r--server/src/emmy/manager.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
new file mode 100644
index 00000000..5f83c9d1
--- /dev/null
+++ b/server/src/emmy/manager.lua
@@ -0,0 +1,62 @@
+local listMgr = require 'vm.list'
+local newClass = require 'emmy.class'
+
+local mt = {}
+mt.__index = mt
+mt.__name = 'emmyMgr'
+
+function mt:flushClass(name)
+ local list = self._class[name]
+ if not list then
+ return
+ end
+ local version = listMgr.getVersion()
+ if version == list.version then
+ return
+ end
+ for srcId in pairs(list) do
+ if not listMgr.get(srcId) then
+ list[srcId] = nil
+ end
+ end
+ if not next(list) then
+ self._class[name] = nil
+ return
+ end
+ list.version = version
+end
+
+function mt:eachClass(name, callback)
+ self:flushClass(name)
+ local list = self._class[name]
+ if not list then
+ return
+ end
+ for _, class in pairs(list) do
+ callback(class)
+ end
+end
+
+function mt:addClass(class, parent)
+ local className = class[1]
+ local list = self._class[className]
+ local version = listMgr.getVersion()
+ if not list then
+ list = {
+ version = version,
+ }
+ self._class[className] = list
+ end
+ list[class.id] = newClass(class, parent)
+ self:flushClass(className)
+end
+
+function mt:remove()
+end
+
+return function ()
+ local self = setmetatable({
+ _class = {},
+ }, mt)
+ return self
+end