summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/meta/Lua 5.4/basic.lua10
-rw-r--r--server/src/core/hover/function.lua19
-rw-r--r--server/src/emmy/return.lua1
-rw-r--r--server/src/parser/ast.lua9
-rw-r--r--server/src/parser/grammar.lua2
-rw-r--r--server/src/vm/function.lua9
-rw-r--r--server/test/hover/init.lua10
7 files changed, 52 insertions, 8 deletions
diff --git a/server/meta/Lua 5.4/basic.lua b/server/meta/Lua 5.4/basic.lua
index 9c301c72..23d87cdb 100644
--- a/server/meta/Lua 5.4/basic.lua
+++ b/server/meta/Lua 5.4/basic.lua
@@ -31,7 +31,15 @@ end
--- 当前解释器版本号。
_VERSION = 'Lua 5.4'
-local next = next
+--- 返回该键的下一个键及其关联的值。
+---@param t table
+---@param index any {optional = 'self'}
+---@return any {name = 'key'}
+---@return any {name = 'value'}
+local function next(t, index)
+end
+
+_G['next'] = next
--- 能迭代表 `t` 中的所有键值对。
---|```lua
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
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 108bc978..bc6df999 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -822,3 +822,13 @@ function <?f?>(x, y, z) end
[=[
function f([x: number [, y: boolean], z: string])
]=]
+
+TEST [[
+---@return string {name = 'key'}
+---@return string {name = 'value'}
+function <?f?>() end
+]]
+[=[
+function f()
+ -> key: string, value: string
+]=]