summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json7
-rw-r--r--meta/Lua 5.4/basic.lua10
-rw-r--r--meta/Lua 5.4/meta.lua10
-rw-r--r--server/src/core/hover/function.lua28
-rw-r--r--server/src/emmy/manager.lua1
-rw-r--r--server/src/emmy/param.lua8
-rw-r--r--server/src/parser/ast.lua16
-rw-r--r--server/src/parser/grammar.lua3
-rw-r--r--server/test/hover/init.lua10
9 files changed, 86 insertions, 7 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 23d65348..bf8535ac 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -15,9 +15,10 @@
"Lua.workspace.maxPreload": 400,
"Lua.workspace.preloadFileSize": 1000,
"Lua.workspace.ignoreDir": [
- "server/locale/",
- "server/libs/",
- "server/src/3rd",
+ "/server/locale/",
+ "/server/libs/",
+ "/server/src/3rd",
+ "/meta/"
],
"Lua.workspace.library": {
"E:/Github/test" : true,
diff --git a/meta/Lua 5.4/basic.lua b/meta/Lua 5.4/basic.lua
new file mode 100644
index 00000000..5c2feb3f
--- /dev/null
+++ b/meta/Lua 5.4/basic.lua
@@ -0,0 +1,10 @@
+--- 独立版Lua的启动参数。
+arg = {}
+
+--- 如果其参数 `v` 的值为假,它就调用 `error`。
+---@overload fun(v:any):any
+---@param v any
+---@param message any {optional = 'self'}
+---@return any
+function assert(v, message)
+end
diff --git a/meta/Lua 5.4/meta.lua b/meta/Lua 5.4/meta.lua
new file mode 100644
index 00000000..efa4dd08
--- /dev/null
+++ b/meta/Lua 5.4/meta.lua
@@ -0,0 +1,10 @@
+---@class any
+---@class string any
+---@class number any
+---@class integer number
+---@class boolean any
+---@class table any
+---@class function any
+---@class nil any
+---@class userdata any
+---@class thread any
diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua
index 5358cfaa..b0971308 100644
--- a/server/src/core/hover/function.lua
+++ b/server/src/core/hover/function.lua
@@ -4,6 +4,7 @@ local function buildValueArgs(func, object, select)
end
local names = {}
local values = {}
+ local options = {}
if func.argValues then
for i, value in ipairs(func.argValues) do
values[i] = value:getType()
@@ -15,6 +16,7 @@ local function buildValueArgs(func, object, select)
local param = func:findEmmyParamByName(arg:getName())
if param then
values[i] = param:getType()
+ options[i] = param:getOption()
end
end
end
@@ -30,11 +32,20 @@ local function buildValueArgs(func, object, select)
max = math.max(#names, #values)
end
for i = start, max do
+ local name = names[i]
+ local value = values[i] or 'any'
+ local option = options[i]
+ if option and option.optional then
+ if i > start then
+ strs[#strs+1] = ' ['
+ else
+ strs[#strs+1] = '['
+ end
+ end
if i > start then
strs[#strs+1] = ', '
end
- local name = names[i]
- local value = values[i] or 'any'
+
if i == select then
strs[#strs+1] = '@ARG'
end
@@ -46,6 +57,10 @@ local function buildValueArgs(func, object, select)
if i == select then
strs[#strs+1] = '@ARG'
end
+
+ if option and option.optional == 'self' then
+ strs[#strs+1] = ']'
+ end
end
if func:hasDots() then
if max > 0 then
@@ -53,6 +68,15 @@ local function buildValueArgs(func, object, select)
end
strs[#strs+1] = '...'
end
+
+ if options then
+ for _, option in pairs(options) do
+ if option.optional == 'after' then
+ strs[#strs+1] = ']'
+ end
+ end
+ end
+
local text = table.concat(strs)
local argLabel = {}
for i = 1, 2 do
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index 11aa899c..1be0be94 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -158,6 +158,7 @@ function mt:addParam(source, bind)
for i = 3, #source do
paramObj:addEnum(source[i][1])
end
+ paramObj:setOption(source.option)
return paramObj
end
diff --git a/server/src/emmy/param.lua b/server/src/emmy/param.lua
index 290ab6e4..6fd41d5a 100644
--- a/server/src/emmy/param.lua
+++ b/server/src/emmy/param.lua
@@ -47,6 +47,14 @@ function mt:eachEnum(callback)
end
end
+function mt:setOption(option)
+ self._option = option
+end
+
+function mt:getOption()
+ return self._option
+end
+
return function (manager, source)
local self = setmetatable({
source = source.id,
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 9903dca2..0e408c73 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1233,9 +1233,23 @@ local Defs = {
...
}
end,
- EmmyParam = function (argName, emmyName, ...)
+ EmmyParam = function (argName, emmyName, options, ...)
+ local option
+ if options then
+ option = {}
+ for _, pair in ipairs(options) do
+ if pair.type == 'pair' then
+ local key = pair[1]
+ local value = pair[2]
+ if key.type == 'name' then
+ option[key[1]] = value[1]
+ end
+ end
+ end
+ end
local emmy = {
type = 'emmyParam',
+ option = option,
argName,
emmyName,
...
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index 50f76d0b..913b0b25 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -560,7 +560,8 @@ EmmyTypeEnums <- %s* '|' %s* String
EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnums*
-EmmyParam <- MustEmmyName %s* EmmyType EmmyTypeEnums*
+EmmyParam <- MustEmmyName %s* EmmyType %s* EmmyOption %s* EmmyTypeEnums*
+EmmyOption <- Table / %nil
EmmyReturn <- EmmyType
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index f1a18c06..108bc978 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -812,3 +812,13 @@ local <toclose> <const> <?x?> = 1
[[
local <toclose> <const> x: number = 1
]]
+
+TEST [[
+---@param x number {optional = 'after'}
+---@param y boolean {optional = 'self'}
+---@param z string
+function <?f?>(x, y, z) end
+]]
+[=[
+function f([x: number [, y: boolean], z: string])
+]=]