diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-28 15:47:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-28 15:47:48 +0800 |
commit | ef00d018e5f3292dd08deeeabfc77e6c75492a67 (patch) | |
tree | aa1e4500d9e122027762935721c1adbc59cfc45d /server/src | |
parent | daee93fb17e8f206e63ab8573566762011a3f1cd (diff) | |
download | lua-language-server-ef00d018e5f3292dd08deeeabfc77e6c75492a67.zip |
支持返回值命名
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/hover/function.lua | 19 | ||||
-rw-r--r-- | server/src/emmy/return.lua | 1 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 9 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 2 | ||||
-rw-r--r-- | server/src/vm/function.lua | 9 |
5 files changed, 33 insertions, 7 deletions
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 |