summaryrefslogtreecommitdiff
path: root/tools/love-api.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-20 17:20:24 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-20 17:20:24 +0800
commit15e011e334099a9c0c6bc34399fb90769600210f (patch)
treebb05a8349a61d6e19d59c8582b5e9e5a965c336a /tools/love-api.lua
parent002e0c1673fdc5bd76331aaa1359cbb0925dad2e (diff)
downloadlua-language-server-15e011e334099a9c0c6bc34399fb90769600210f.zip
update
Diffstat (limited to 'tools/love-api.lua')
-rw-r--r--tools/love-api.lua46
1 files changed, 28 insertions, 18 deletions
diff --git a/tools/love-api.lua b/tools/love-api.lua
index 0d751531..bb44c11c 100644
--- a/tools/love-api.lua
+++ b/tools/love-api.lua
@@ -12,6 +12,7 @@ fs.create_directories(libraryPath)
local knownTypes = {
['nil'] = 'nil',
+ ['any'] = 'any',
['boolean'] = 'boolean',
['number'] = 'number',
['integer'] = 'integer',
@@ -25,24 +26,27 @@ local knownTypes = {
['light userdata'] = 'lightuserdata'
}
-local function getTypeName(class, name)
+local function getTypeName(name)
if knownTypes[name] then
return knownTypes[name]
end
- return class .. '.' .. name
+ return 'love.' .. name
end
-local function buildType(class, param)
- return getTypeName(class, param.type)
+local function buildType(param)
+ if param.table then
+ getTypeName(param.type)
+ end
+ return getTypeName(param.type)
end
-local function buildSuper(class, tp)
+local function buildSuper(tp)
if not tp.supertypes then
return ''
end
local parents = {}
for _, parent in ipairs(tp.supertypes) do
- parents[#parents+1] = ('%s.%s'):format(class, parent)
+ parents[#parents+1] = getTypeName(parent)
end
return (': %s'):format(table.concat(parents, ', '))
end
@@ -54,19 +58,23 @@ local function buildFunction(class, func, node)
text[#text+1] = '---'
local params = {}
for _, param in ipairs(func.variants[1].arguments or {}) do
- params[#params+1] = param.name
- text[#text+1] = ('---@param %s %s # %s'):format(
- param.name,
- buildType(class, param),
- param.description
- )
+ for paramName in param.name:gmatch '[%a_][%w_]+' do
+ params[#params+1] = paramName
+ text[#text+1] = ('---@param %s %s # %s'):format(
+ paramName,
+ buildType(param),
+ param.description
+ )
+ end
end
for _, rtn in ipairs(func.variants[1].returns or {}) do
- text[#text+1] = ('---@return %s %s # %s'):format(
- buildType(class, rtn),
- rtn.name,
- rtn.description
- )
+ for returnName in rtn.name:gmatch '[%a_][%w_]+' do
+ text[#text+1] = ('---@return %s %s # %s'):format(
+ buildType(rtn),
+ returnName,
+ rtn.description
+ )
+ end
end
text[#text+1] = ('function %s%s(%s) end'):format(
node,
@@ -80,6 +88,8 @@ local function buildFile(class, defs)
local filePath = libraryPath / (class .. '.lua')
local text = {}
+ text[#text+1] = '---@meta'
+ text[#text+1] = ''
text[#text+1] = ('---@class %s'):format(class)
text[#text+1] = ('%s = {}'):format(class)
@@ -90,7 +100,7 @@ local function buildFile(class, defs)
for _, tp in ipairs(defs.types or {}) do
text[#text+1] = ''
- text[#text+1] = ('---@class %s%s'):format(getTypeName(class, tp.name), buildSuper(class, tp))
+ text[#text+1] = ('---@class %s%s'):format(getTypeName(tp.name), buildSuper(tp))
text[#text+1] = ('local %s = {}'):format(tp.name)
for _, func in ipairs(tp.functions or {}) do
text[#text+1] = ''