From ef00d018e5f3292dd08deeeabfc77e6c75492a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 28 Jun 2019 15:47:48 +0800 Subject: =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=94=E5=9B=9E=E5=80=BC=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/hover/function.lua | 19 +++++++++++++++++-- server/src/emmy/return.lua | 1 + server/src/parser/ast.lua | 9 +++++---- server/src/parser/grammar.lua | 2 +- server/src/vm/function.lua | 9 +++++++++ 5 files changed, 33 insertions(+), 7 deletions(-) (limited to 'server/src') diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index 620eb054..c5c7a118 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -106,9 +106,24 @@ local function buildValueReturns(func) return '' end local strs = {} + local n = 0 + func:eachEmmyReturn(function (emmy) + n = n + 1 + local name = '' + if emmy.option and emmy.option.name then + name = emmy.option.name .. ': ' + end + local rtn = func:getReturn(n) + if not rtn then + strs[#strs+1] = name .. 'any' + return + end + strs[#strs+1] = name .. rtn:getType() + end) if func.returns then - for i, rtn in ipairs(func.returns) do - strs[i] = rtn:getType() + for i = n + 1, #func.returns do + local rtn = func:getReturn(i) + strs[#strs+1] = rtn:getType() end end if #strs == 0 then diff --git a/server/src/emmy/return.lua b/server/src/emmy/return.lua index a347267c..a23f3ac9 100644 --- a/server/src/emmy/return.lua +++ b/server/src/emmy/return.lua @@ -28,6 +28,7 @@ end return function (manager, source) local self = setmetatable({ source = source.id, + option = source.option, _manager = manager, }, mt) return self diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 08f7fdd3..c14328f0 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1245,13 +1245,14 @@ local Defs = { emmy.finish = emmy[#emmy].finish return emmy end, - EmmyReturn = function (...) + EmmyReturn = function (type, option) local emmy = { type = 'emmyReturn', - ... + option = option, + start = type.start, + finish = type.finish, + [1] = type, } - emmy.start = emmy[1].start - emmy.finish = emmy[#emmy].finish return emmy end, EmmyField = function (access, fieldName, ...) diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 2967ac3c..da850250 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -569,7 +569,7 @@ EmmyParam <- MustEmmyName %s* EmmyType %s* EmmyOption %s* EmmyTypeEnum* EmmyOption <- Table? -> EmmyOption -EmmyReturn <- EmmyType +EmmyReturn <- EmmyType EmmyOption EmmyField <- (EmmyFieldAccess MustEmmyName %s* EmmyType) EmmyFieldAccess <- ({'public'} Cut %s*) diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 8f7ac6c2..beca5769 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -339,6 +339,15 @@ function mt:run(vm) end end +function mt:eachEmmyReturn(callback) + if not self._emmyReturns then + return + end + for _, rtn in ipairs(self._emmyReturns) do + callback(rtn) + end +end + function mt:setArgs(values) for i = 1, #self.argValues do self.argValues[i] = nil -- cgit v1.2.3