diff options
-rw-r--r-- | server/meta/Lua 5.4/basic.lua | 7 | ||||
-rw-r--r-- | server/src/core/hover/function.lua | 2 | ||||
-rw-r--r-- | server/src/emmy/alias.lua | 6 | ||||
-rw-r--r-- | server/test/crossfile/hover.lua | 28 |
4 files changed, 35 insertions, 8 deletions
diff --git a/server/meta/Lua 5.4/basic.lua b/server/meta/Lua 5.4/basic.lua index 6b0bff8e..20a60e1d 100644 --- a/server/meta/Lua 5.4/basic.lua +++ b/server/meta/Lua 5.4/basic.lua @@ -9,9 +9,7 @@ arg = {} function assert(v, message) end ----@overload fun() ----@overload fun(opt:string):any ----@param opt string {optional = 'after'} +---@alias GCOption string ---| '"collect"' {comment = '做一次完整的垃圾收集循环。', default = true} ---| '"stop"' {comment = '停止垃圾收集器的运行。'} ---| '"restart"' {comment = '重启垃圾收集器的自动运行。'} @@ -22,6 +20,9 @@ end ---| '"incremental"' {comment = '改变收集器模式为增量模式。'} ---| '"generational"' {comment = '改变收集器模式为分代模式。'} ---| '"isrunning"' {comment = '返回表示收集器是否在工作的布尔值。'} +---@overload fun() +---@overload fun(opt:GCOption):any +---@param opt GCOption {optional = 'after'} ---@param arg integer {optional = 'self'} ---@return any function collectgarbage(opt, arg) diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index 5976806c..b3bbb428 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -132,7 +132,7 @@ local function buildEnum(func) param:eachEnum(function (enum, option) if first then first = false - strs[#strs+1] = ('\n%s:%s'):format(param:getName(), param:getType()) + strs[#strs+1] = ('\n%s: %s'):format(param:getName(), param:getType()) end if option and option.default then strs[#strs+1] = ('\n |>%s'):format(enum) diff --git a/server/src/emmy/alias.lua b/server/src/emmy/alias.lua index be47cb4f..7e015542 100644 --- a/server/src/emmy/alias.lua +++ b/server/src/emmy/alias.lua @@ -21,13 +21,13 @@ function mt:bindType(type) end end -function mt:addEnum(enum) - self._enum[#self._enum+1] = enum +function mt:addEnum(enum, option) + self._enum[#self._enum+1] = {enum, option} end function mt:eachEnum(callback) for _, enum in ipairs(self._enum) do - callback(enum) + callback(enum[1], enum[2]) end end diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua index 543a7ccf..fbabe0b0 100644 --- a/server/test/crossfile/hover.lua +++ b/server/test/crossfile/hover.lua @@ -279,7 +279,33 @@ TEST { name = 'f', enum = [[ -x:string +x: string + | '选项1' -- 注释1 + |>'选项2' -- 注释2]] + } +} + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = [[ + ---@alias option + ---| "'选项1'" {comment = '注释1'} + ---| "'选项2'" {comment = '注释2', default = true} + ---@param x option + function <?f?>(x) end + ]] + }, + hover = { + label = 'function f(x: option)', + name = 'f', + enum = [[ + +x: option | '选项1' -- 注释1 |>'选项2' -- 注释2]] } |