diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-18 11:42:45 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-18 11:42:45 +0800 |
commit | 04c3ce15f1515b11e43e4630888e323c6372b409 (patch) | |
tree | cfd2659fdaac0499416f8bf1406641f35edd6cb2 /server/src/emmy | |
parent | 1c0416baecc6db9720beb18d5abfc3b7ef33ffbe (diff) | |
download | lua-language-server-04c3ce15f1515b11e43e4630888e323c6372b409.zip |
emmy.class
Diffstat (limited to 'server/src/emmy')
-rw-r--r-- | server/src/emmy/class.lua | 16 | ||||
-rw-r--r-- | server/src/emmy/init.lua | 1 | ||||
-rw-r--r-- | server/src/emmy/manager.lua | 62 |
3 files changed, 79 insertions, 0 deletions
diff --git a/server/src/emmy/class.lua b/server/src/emmy/class.lua new file mode 100644 index 00000000..69d731ee --- /dev/null +++ b/server/src/emmy/class.lua @@ -0,0 +1,16 @@ +local mt = {} +mt.__index = mt +mt.type = 'emmy.class' + +function mt:getType() + return self._name +end + +return function (class, parent) + local self = setmetatable({ + name = class[1], + source = class.id, + parent = parent and parent.id, + }) + return self +end diff --git a/server/src/emmy/init.lua b/server/src/emmy/init.lua new file mode 100644 index 00000000..769c9e05 --- /dev/null +++ b/server/src/emmy/init.lua @@ -0,0 +1 @@ +return require 'vm.emmy.emmy' 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 |