summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/meta/Lua 5.4/basic.lua20
-rw-r--r--server/src/core/completion.lua15
-rw-r--r--server/src/core/hover/function.lua12
-rw-r--r--server/src/emmy/alias.lua6
-rw-r--r--server/src/emmy/manager.lua8
-rw-r--r--server/src/emmy/param.lua6
-rw-r--r--server/src/parser/ast.lua15
-rw-r--r--server/src/parser/grammar.lua4
-rw-r--r--server/test/completion/init.lua4
-rw-r--r--server/test/crossfile/hover.lua8
10 files changed, 50 insertions, 48 deletions
diff --git a/server/meta/Lua 5.4/basic.lua b/server/meta/Lua 5.4/basic.lua
index 20a60e1d..9c301c72 100644
--- a/server/meta/Lua 5.4/basic.lua
+++ b/server/meta/Lua 5.4/basic.lua
@@ -10,16 +10,16 @@ function assert(v, message)
end
---@alias GCOption string
----| '"collect"' {comment = '做一次完整的垃圾收集循环。', default = true}
----| '"stop"' {comment = '停止垃圾收集器的运行。'}
----| '"restart"' {comment = '重启垃圾收集器的自动运行。'}
----| '"count"' {comment = '以 K 字节数为单位返回 Lua 使用的总内存数。'}
----| '"step"' {comment = '单步运行垃圾收集器。'}
----| '"setpause"' {comment = '设置收集器的 `间歇率`。'}
----| '"setstepmul"' {comment = '设置收集器的 `步进倍率`。'}
----| '"incremental"' {comment = '改变收集器模式为增量模式。'}
----| '"generational"' {comment = '改变收集器模式为分代模式。'}
----| '"isrunning"' {comment = '返回表示收集器是否在工作的布尔值。'}
+---| > '"collect"' # 做一次完整的垃圾收集循环。
+---| '"stop"' # 停止垃圾收集器的运行。
+---| '"restart"' # 重启垃圾收集器的自动运行。
+---| '"count"' # 以 K 字节数为单位返回 Lua 使用的总内存数。
+---| '"step"' # 单步运行垃圾收集器。
+---| '"setpause"' # 设置收集器的 `间歇率`。
+---| '"setstepmul"' # 设置收集器的 `步进倍率`。
+---| '"incremental"' # 改变收集器模式为增量模式。
+---| '"generational"' # 改变收集器模式为分代模式。
+---| '"isrunning"' # 返回表示收集器是否在工作的布尔值。
---@overload fun()
---@overload fun(opt:GCOption):any
---@param opt GCOption {optional = 'after'}
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index ddbe7271..6ab3c565 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -663,14 +663,14 @@ local function searchEnumAsLib(vm, source, word, callback, pos, args, lib)
end
end
-local function buildEmmyEnumComment(option, data)
- if not option or not option.comment then
+local function buildEmmyEnumComment(enum, data)
+ if not enum.comment then
return data
end
if not data then
data = {}
end
- data.documentation = tostring(option.comment)
+ data.documentation = tostring(enum.comment)
return data
end
@@ -688,18 +688,19 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun
return
end
- param:eachEnum(function (str, option)
+ param:eachEnum(function (enum)
+ local str = enum[1]
if matchKey(word, str) then
local strSource = parser:ast(tostring(str), 'String')
if strSource then
if source.type == 'string' then
local data = buildTextEdit(source.start, source.finish, strSource[1], source[2])
- callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option, data))
+ callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(enum, data))
else
- callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option))
+ callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(enum))
end
else
- callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option))
+ callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(enum))
end
end
end)
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua
index b3bbb428..620eb054 100644
--- a/server/src/core/hover/function.lua
+++ b/server/src/core/hover/function.lua
@@ -129,18 +129,18 @@ local function buildEnum(func)
local strs = {}
for _, param in ipairs(params) do
local first = true
- param:eachEnum(function (enum, option)
+ param:eachEnum(function (enum)
if first then
first = false
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)
+ if enum.default then
+ strs[#strs+1] = ('\n |>%s'):format(enum[1])
else
- strs[#strs+1] = ('\n | %s'):format(enum)
+ strs[#strs+1] = ('\n | %s'):format(enum[1])
end
- if option and option.comment then
- strs[#strs+1] = ' -- ' .. option.comment
+ if enum.comment then
+ strs[#strs+1] = ' -- ' .. enum.comment
end
end)
end
diff --git a/server/src/emmy/alias.lua b/server/src/emmy/alias.lua
index 7e015542..be47cb4f 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, option)
- self._enum[#self._enum+1] = {enum, option}
+function mt:addEnum(enum)
+ self._enum[#self._enum+1] = enum
end
function mt:eachEnum(callback)
for _, enum in ipairs(self._enum) do
- callback(enum[1], enum[2])
+ callback(enum)
end
end
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index 931c9449..0407bbc0 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -136,7 +136,7 @@ function mt:addAlias(source, typeObj)
local list = self:getClass(aliasName)
list[source.id] = aliasObj
for i = 3, #source do
- aliasObj:addEnum(source[i][1][1], source[i].option)
+ aliasObj:addEnum(source[i])
end
return aliasObj
end
@@ -149,14 +149,14 @@ function mt:addParam(source, bind)
paramObj:bindType(bind)
self:eachClass(bind:getName(), function (class)
if class.type == 'emmy.alias' then
- class:eachEnum(function (enum, option)
- paramObj:addEnum(enum, option)
+ class:eachEnum(function (enum)
+ paramObj:addEnum(enum)
end)
end
end)
end
for i = 3, #source do
- paramObj:addEnum(source[i][1][1], source[i].option)
+ paramObj:addEnum(source[i])
end
paramObj:setOption(source.option)
return paramObj
diff --git a/server/src/emmy/param.lua b/server/src/emmy/param.lua
index 65791fd6..12ac0633 100644
--- a/server/src/emmy/param.lua
+++ b/server/src/emmy/param.lua
@@ -37,13 +37,13 @@ function mt:bindGeneric(generic)
end
end
-function mt:addEnum(enum, option)
- self._enum[#self._enum+1] = {enum, option}
+function mt:addEnum(enum)
+ self._enum[#self._enum+1] = enum
end
function mt:eachEnum(callback)
for _, enum in ipairs(self._enum) do
- callback(enum[1], enum[2])
+ callback(enum)
end
end
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index f9a6d53d..08f7fdd3 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1335,14 +1335,13 @@ local Defs = {
end
return option
end,
- EmmyTypeEnum = function (enum, option)
- return {
- type = 'emmyEnum',
- option = option,
- start = enum.start,
- finish = enum.finish,
- [1] = enum,
- }
+ EmmyTypeEnum = function (default, enum, comment)
+ enum.type = 'emmyEnum'
+ if default ~= '' then
+ enum.default = true
+ end
+ enum.comment = comment
+ return enum
end,
-- 捕获错误
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index c53597dd..2967ac3c 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -558,8 +558,10 @@ EmmyTypeName <- EmmyFunctionType
/ EmmyTableType
/ EmmyArrayType
/ MustEmmyName
-EmmyTypeEnum <- %s* (%nl %s* '---')? '|' %s* (String EmmyOption)
+EmmyTypeEnum <- %s* (%nl %s* '---')? '|' EmmyEnum
-> EmmyTypeEnum
+EmmyEnum <- %s* {'>'?} %s* String (EmmyEnumComment / (!%nl !'|' .)*)
+EmmyEnumComment <- %s* '#' %s* {(!%nl .)*}
EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnum*
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 98d6611d..bc17901e 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -1341,8 +1341,8 @@ zz$
TEST [[
---@param x string
----| "'选项1'" {comment = '注释1'}
----| "'选项2'" {comment = '注释2'}
+---| "'选项1'" # 注释1
+---| "'选项2'" # 注释2
function f(x) end
f($)
diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua
index fbabe0b0..19e8912f 100644
--- a/server/test/crossfile/hover.lua
+++ b/server/test/crossfile/hover.lua
@@ -269,8 +269,8 @@ TEST {
path = 'b.lua',
content = [[
---@param x string
- ---| "'选项1'" {comment = '注释1'}
- ---| "'选项2'" {comment = '注释2', default = true}
+ ---| "'选项1'" # 注释1
+ ---| > "'选项2'" # 注释2
function <?f?>(x) end
]]
},
@@ -294,8 +294,8 @@ TEST {
path = 'b.lua',
content = [[
---@alias option
- ---| "'选项1'" {comment = '注释1'}
- ---| "'选项2'" {comment = '注释2', default = true}
+ ---| "'选项1'" # 注释1
+ ---| > "'选项2'" # 注释2
---@param x option
function <?f?>(x) end
]]