diff options
-rw-r--r-- | server/meta/Lua 5.4/basic.lua | 20 | ||||
-rw-r--r-- | server/src/core/hover/function.lua | 18 | ||||
-rw-r--r-- | server/test/crossfile/hover.lua | 25 |
3 files changed, 53 insertions, 10 deletions
diff --git a/server/meta/Lua 5.4/basic.lua b/server/meta/Lua 5.4/basic.lua index d94a3e10..7da03b4b 100644 --- a/server/meta/Lua 5.4/basic.lua +++ b/server/meta/Lua 5.4/basic.lua @@ -12,16 +12,16 @@ end ---@overload fun() ---@overload fun(opt:string):any ---@param opt string {optional = 'after'} ----| '"collect"' ----| '"stop"' ----| '"restart"' ----| '"count"' ----| '"step"' ----| '"setpause"' ----| '"setstepmul"' ----| '"incremental"' ----| '"generational"' ----| '"isrunning"' +---| '"collect"' {comment = '做一次完整的垃圾收集循环。'} +---| '"stop"' {comment = '停止垃圾收集器的运行。'} +---| '"restart"' {comment = '重启垃圾收集器的自动运行。'} +---| '"count"' {comment = '以 K 字节数为单位返回 Lua 使用的总内存数。'} +---| '"step"' {comment = '单步运行垃圾收集器。'} +---| '"setpause"' {comment = '设置收集器的 `间歇率`。'} +---| '"setstepmul"' {comment = '设置收集器的 `步进倍率`。'} +---| '"incremental"' {comment = '改变收集器模式为增量模式。'} +---| '"generational"' {comment = '改变收集器模式为分代模式。'} +---| '"isrunning"' {comment = '返回表示收集器是否在工作的布尔值。'} ---@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 2dc15996..b23809f8 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -124,6 +124,24 @@ local function buildEnum(func) if not params then return nil end + local strs = {} + for _, param in ipairs(params) do + local first = true + param:eachEnum(function (enum, option) + if first then + first = false + strs[#strs+1] = ('\n%s:%s'):format(param:getName(), param:getType()) + end + strs[#strs+1] = ('\n | %s'):format(enum) + if option and option.comment then + strs[#strs+1] = ' -- ' .. option.comment + end + end) + end + if #strs == 0 then + return nil + end + return table.concat(strs) end local function getComment(func) diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua index b0b8ab61..c6eda13b 100644 --- a/server/test/crossfile/hover.lua +++ b/server/test/crossfile/hover.lua @@ -259,3 +259,28 @@ TEST { description = 'abc', } } + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = [[ + ---@param x string + ---| "'选项1'" {comment = '注释1'} + ---| "'选项2'" {comment = '注释2'} + function <?f?>(x) end + ]] + }, + hover = { + label = 'function f(x: string)', + name = 'f', + enum = [[ + +x:string + | '选项1' -- 注释1 + | '选项2' -- 注释2]] + } +} |