diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-28 10:33:50 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-28 10:33:50 +0800 |
commit | ec3eb3c504e2c13bec721fbe521ec2ac43ce7820 (patch) | |
tree | 7ed5cdf06f3a8cf4bd9a4fd07d19bd226cc291dc /server | |
parent | 4fc32a8f7f410af9e2952d08ab98c74547a4fc9f (diff) | |
download | lua-language-server-ec3eb3c504e2c13bec721fbe521ec2ac43ce7820.zip |
emmy.return
Diffstat (limited to 'server')
-rw-r--r-- | server/src/emmy/manager.lua | 10 | ||||
-rw-r--r-- | server/src/emmy/return.lua | 26 | ||||
-rw-r--r-- | server/src/vm/emmy.lua | 19 | ||||
-rw-r--r-- | server/src/vm/function.lua | 8 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 2 |
5 files changed, 60 insertions, 5 deletions
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua index d8b3b656..e0b60304 100644 --- a/server/src/emmy/manager.lua +++ b/server/src/emmy/manager.lua @@ -4,6 +4,7 @@ local newType = require 'emmy.type' local newTypeUnit = require 'emmy.typeUnit' local newAlias = require 'emmy.alias' local newParam = require 'emmy.param' +local newReturn = require 'emmy.return' local mt = {} mt.__index = mt @@ -106,14 +107,17 @@ function mt:addAlias(source, typeObj) end function mt:addParam(source, typeObj) - local paramName = source[1][1] local paramObj = newParam(self, source) paramObj:bindType(typeObj) - local list = self:getClass(paramName) - list[source.id] = paramObj return paramObj end +function mt:addReturn(source, typeObj) + local returnObj = newReturn(self, source) + returnObj:bindType(typeObj) + return returnObj +end + function mt:remove() end diff --git a/server/src/emmy/return.lua b/server/src/emmy/return.lua new file mode 100644 index 00000000..49f6e260 --- /dev/null +++ b/server/src/emmy/return.lua @@ -0,0 +1,26 @@ +local listMgr = require 'vm.list' + +---@class EmmyReturn +local mt = {} +mt.__index = mt +mt.type = 'emmy.return' + +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 + +return function (manager, source) + local self = setmetatable({ + source = source.id, + _manager = manager, + }, mt) + return self +end diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index f183de73..4c611d59 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -3,6 +3,7 @@ local mt = require 'vm.manager' function mt:clearEmmy() self._emmy = nil self._emmyParams = nil + self._emmyReturns = nil end function mt:doEmmy(action) @@ -16,6 +17,7 @@ function mt:doEmmy(action) elseif tp == 'emmyParam' then self:doEmmyParam(action) elseif tp == 'emmyReturn' then + self:doEmmyReturn(action) elseif tp == 'emmyField' then elseif tp == 'emmyGeneric' then elseif tp == 'emmyVararg' then @@ -48,6 +50,12 @@ function mt:getEmmyParams() return params end +function mt:getEmmyReturns() + local returns = self._emmyReturns + self._emmyReturns = nil + return returns +end + function mt:doEmmyClass(action) ---@type emmyMgr local emmyMgr = self.emmyMgr @@ -110,6 +118,17 @@ function mt:doEmmyParam(action) self:addEmmyParam(param) end +function mt:doEmmyReturn(action) + ---@type emmyMgr + local emmyMgr = self.emmyMgr + self:instantSource(action) + local type = self:doEmmyType(action[1]) + local rtn = emmyMgr:addReturn(action, type) + action:set('emmy.return', rtn) + self._emmy = nil + self:addEmmyReturn(rtn) +end + function mt:doEmmyIncomplete(action) self:instantSource(action) end diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 8bc38970..3fb3db69 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -381,7 +381,7 @@ function mt:markGlobal() end end -function mt:setEmmyParams(params) +function mt:setEmmy(params, returns) if params then self._emmyParams = params for _, param in ipairs(params) do @@ -389,6 +389,12 @@ function mt:setEmmyParams(params) param:getSource()[1]:set('emmy function', self) end end + if returns then + self._emmyReturns = returns + for _, rtn in ipairs(returns) do + rtn:getSource():set('emmy function', self) + end + end end function mt:getEmmyParams() diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index bb996066..56fec644 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -1075,7 +1075,7 @@ end function mt:createFunction(source) local value = self:createValue('function', source) local func = functionMgr.create(source) - func:setEmmyParams(self:getEmmyParams()) + func:setEmmy(self:getEmmyParams(), self:getEmmyReturns()) value:setFunction(func) value:setType('function', 1.0) if source:getUri() == self.uri then |