summaryrefslogtreecommitdiff
path: root/tools/lovr-api.lua
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2022-08-11 19:36:36 +0800
committerCppCXY <812125110@qq.com>2022-08-11 19:36:36 +0800
commitff9103ae4001d8e520171b99cd192997fc689bc9 (patch)
tree04c0b685e81aac48210604dc12d24b91862a36d9 /tools/lovr-api.lua
parent40f191a85ea21bb64c427f9dab4bc597e2a0ea1b (diff)
parent82bcfef9037c26681993c94b2f92b68d335de3c6 (diff)
downloadlua-language-server-ff9103ae4001d8e520171b99cd192997fc689bc9.zip
Merge branch 'master' of github.com:CppCXY/lua-language-server
Diffstat (limited to 'tools/lovr-api.lua')
-rw-r--r--tools/lovr-api.lua32
1 files changed, 28 insertions, 4 deletions
diff --git a/tools/lovr-api.lua b/tools/lovr-api.lua
index ca7c414e..f045afa8 100644
--- a/tools/lovr-api.lua
+++ b/tools/lovr-api.lua
@@ -51,6 +51,22 @@ local function formatIndex(key)
return ('[%q]'):format(key)
end
+local function getOptional(param)
+ if param.type == 'table' then
+ if not param.table then
+ return ''
+ end
+ for _, field in ipairs(param.table) do
+ if field.default == nil then
+ return ''
+ end
+ end
+ return '?'
+ else
+ return (param.default ~= nil) and '?' or ''
+ end
+end
+
local buildType
local function buildDocTable(tbl)
@@ -116,9 +132,9 @@ local function buildDocFunc(variant, overload)
params[#params+1] = '...'
else
if param.name:find '^[\'"]' then
- params[#params+1] = ('%s: %s|%q'):format(param.name:sub(2, -2), getTypeName(param.type), param.name)
+ params[#params+1] = ('%s%s: %s|%s'):format(param.name, getOptional(param), getTypeName(param.type), param.name)
else
- params[#params+1] = ('%s: %s'):format(param.name, getTypeName(param.type))
+ params[#params+1] = ('%s%s: %s'):format(param.name, getOptional(param), getTypeName(param.type))
end
end
end
@@ -152,7 +168,15 @@ local function buildFunction(func, typeName)
params[#params+1] = paramName
text[#text+1] = ('---@param %s%s %s # %s'):format(
paramName,
- param.default == nil and '' or '?',
+ getOptional(param),
+ buildType(param),
+ param.description
+ )
+ end
+
+ if param.name == "..." then
+ params[#params+1] = param.name
+ text[#text+1] = ('---@vararg %s # %s'):format(
buildType(param),
param.description
)
@@ -211,7 +235,7 @@ local function buildFile(defs)
text[#text+1] = ('---@alias %s'):format(getTypeName(enum.name))
for _, constant in ipairs(enum.values) do
text[#text+1] = buildDescription(constant.description, constant.notes)
- text[#text+1] = ([[---| '%s']]):format(('%q'):format(constant.name):gsub("'", "\\'"))
+ text[#text+1] = ([[---| %q]]):format(constant.name)
end
end