diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-28 10:51:59 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-28 10:51:59 +0800 |
commit | fdbc780ec38812ad4f63dc1a5cbda2c0d07f7003 (patch) | |
tree | b7e8528299ad9e0c6d8d228bc11e22bf5493dd6a /server | |
parent | ec3eb3c504e2c13bec721fbe521ec2ac43ce7820 (diff) | |
download | lua-language-server-fdbc780ec38812ad4f63dc1a5cbda2c0d07f7003.zip |
实现emmy.return
Diffstat (limited to 'server')
-rw-r--r-- | server/src/vm/emmy.lua | 7 | ||||
-rw-r--r-- | server/src/vm/function.lua | 10 | ||||
-rw-r--r-- | server/src/vm/manager.lua | 1 | ||||
-rw-r--r-- | server/test/hover/init.lua | 11 |
4 files changed, 29 insertions, 0 deletions
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index 4c611d59..34312831 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -44,6 +44,13 @@ function mt:addEmmyParam(param) self._emmyParams[#self._emmyParams+1] = param end +function mt:addEmmyReturn(rtn) + if not self._emmyReturns then + self._emmyReturns = {} + end + self._emmyReturns[#self._emmyReturns+1] = rtn +end + function mt:getEmmyParams() local params = self._emmyParams self._emmyParams = nil diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 3fb3db69..4c2f0be5 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -227,6 +227,7 @@ function mt:needSkip() return self._runed > 3 end +---@param vm VM function mt:run(vm) if self._removed then return @@ -265,6 +266,15 @@ function mt:run(vm) self._dots:push(self.argValues[i]) end end + + -- 填充返回值 + if self._emmyReturns then + for i, rtn in ipairs(self._emmyReturns) do + local value = vm:createValue('nil', rtn:getSource()) + value:setEmmy(rtn:bindType()) + self:setReturn(i, value) + end + end end function mt:setArgs(values) diff --git a/server/src/vm/manager.lua b/server/src/vm/manager.lua index 2016465b..5f6a9b6a 100644 --- a/server/src/vm/manager.lua +++ b/server/src/vm/manager.lua @@ -1,3 +1,4 @@ +---@class VM local mt = {} mt.__index = mt mt.type = 'vm' diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua index 639789e0..4b4d0c25 100644 --- a/server/test/hover/init.lua +++ b/server/test/hover/init.lua @@ -597,3 +597,14 @@ end [[ local v<value>: *Class {} ]] + +TEST [[ +---@return A|B +---@return C +local function <?f?>() +end +]] +[[ +function f() + -> A|B, C +]] |