summaryrefslogtreecommitdiff
path: root/tools/lovr-api.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-11-01 21:13:25 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-11-01 21:13:25 +0800
commite77cf61fa3558f6d9ec1d6cee4571bb8a1440e6e (patch)
tree2c87ea836a0773c308c7377e925f8f2ad734e384 /tools/lovr-api.lua
parent58a62076ca0f8ce7441d2a42cfb8fe2fc7a75bbc (diff)
downloadlua-language-server-e77cf61fa3558f6d9ec1d6cee4571bb8a1440e6e.zip
update lovr
Diffstat (limited to 'tools/lovr-api.lua')
-rw-r--r--tools/lovr-api.lua31
1 files changed, 24 insertions, 7 deletions
diff --git a/tools/lovr-api.lua b/tools/lovr-api.lua
index 36b29929..6bbc52b4 100644
--- a/tools/lovr-api.lua
+++ b/tools/lovr-api.lua
@@ -32,6 +32,9 @@ end
---@param names string
local function getTypeName(names)
+ if names == '*' then
+ return 'any'
+ end
local types = {}
names = names:gsub('%sor%s', '|')
for name in names:gmatch '[^|]+' do
@@ -64,7 +67,7 @@ function buildType(param)
if param.table then
return buildDocTable(param.table)
end
- if param.type and param.type ~= '*' then
+ if param.type then
return getTypeName(param.type)
end
return 'any'
@@ -186,12 +189,6 @@ local function buildFile(defs)
end
end
- for _, cb in ipairs(defs.callbacks or {}) do
- text[#text+1] = ''
- text[#text+1] = buildDescription(cb.description)
- text[#text+1] = ('---@alias %s %s'):format(getTypeName(cb.name), buildMultiDocFunc(cb))
- end
-
for _, enum in ipairs(defs.enums or {}) do
text[#text+1] = ''
text[#text+1] = buildDescription(enum.description)
@@ -212,6 +209,26 @@ local function buildFile(defs)
fsu.saveFile(filePath, table.concat(text, '\n'))
end
+local function buildCallback(defs)
+ local filePath = libraryPath / ('callback.lua')
+ local text = {}
+
+ text[#text+1] = '---@meta'
+
+ for _, cb in ipairs(defs.callbacks or {}) do
+ text[#text+1] = ''
+ text[#text+1] = buildDescription(cb.description)
+ text[#text+1] = ('---@type %s'):format(buildMultiDocFunc(cb))
+ text[#text+1] = ('%s = nil'):format(cb.key)
+ end
+
+ text[#text+1] = ''
+
+ fsu.saveFile(filePath, table.concat(text, '\n'))
+end
+
+buildCallback(api)
+
for _, module in ipairs(api.modules) do
buildFile(module)
end