summaryrefslogtreecommitdiff
path: root/server/src/emmy
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-28 20:09:43 +0800
committersumneko <sumneko@hotmail.com>2019-04-28 20:09:43 +0800
commit0bc67627a4409a08e34be0b44cba928cdacf8192 (patch)
treea78bf45ded637b3a6424653745895b6c327cb578 /server/src/emmy
parentb4ed749782ba58140c8d7878e4b27ec6b3d2fffb (diff)
downloadlua-language-server-0bc67627a4409a08e34be0b44cba928cdacf8192.zip
emmy.field
Diffstat (limited to 'server/src/emmy')
-rw-r--r--server/src/emmy/class.lua17
-rw-r--r--server/src/emmy/field.lua40
-rw-r--r--server/src/emmy/manager.lua8
3 files changed, 65 insertions, 0 deletions
diff --git a/server/src/emmy/class.lua b/server/src/emmy/class.lua
index 84854fc5..a7417210 100644
--- a/server/src/emmy/class.lua
+++ b/server/src/emmy/class.lua
@@ -33,6 +33,23 @@ function mt:eachChild(callback)
end)
end
+function mt:addField(field)
+ if not self._fields then
+ self._fields = {}
+ end
+ self._fields[#self._fields+1] = field
+end
+
+function mt:eachField(callback)
+ if not self._fields then
+ return
+ end
+ ---@param field EmmyField
+ for _, field in ipairs(self._fields) do
+ callback(field)
+ end
+end
+
return function (manager, source)
local self = setmetatable({
name = source[1][1],
diff --git a/server/src/emmy/field.lua b/server/src/emmy/field.lua
new file mode 100644
index 00000000..d7dfbe98
--- /dev/null
+++ b/server/src/emmy/field.lua
@@ -0,0 +1,40 @@
+local listMgr = require 'vm.list'
+
+---@class EmmyField
+local mt = {}
+mt.__index = mt
+mt.type = 'emmy.field'
+
+function mt:getName()
+ return self.name
+end
+
+function mt:getSource()
+ return listMgr.get(self.source)
+end
+
+function mt:bindType(type)
+ if type then
+ self._bindType = type
+ else
+ return self._bindType
+ end
+end
+
+function mt:bindValue(value)
+ if value then
+ self._bindValue = value
+ else
+ return self._bindValue
+ end
+end
+
+return function (manager, source)
+ local self = setmetatable({
+ name = source[2][1],
+ source = source.id,
+ visible = source[1],
+ _manager = manager,
+ }, mt)
+ return self
+end
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index e0b60304..7875e322 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -5,6 +5,7 @@ local newTypeUnit = require 'emmy.typeUnit'
local newAlias = require 'emmy.alias'
local newParam = require 'emmy.param'
local newReturn = require 'emmy.return'
+local newField = require 'emmy.field'
local mt = {}
mt.__index = mt
@@ -118,6 +119,13 @@ function mt:addReturn(source, typeObj)
return returnObj
end
+function mt:addField(source, typeObj, value)
+ local fieldObj = newField(self, source)
+ fieldObj:bindType(typeObj)
+ fieldObj:bindValue(value)
+ return fieldObj
+end
+
function mt:remove()
end