summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-12 21:16:48 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-12 21:16:48 +0800
commit4e52738f7a315085505ffdbefe9ce6722ec3965f (patch)
tree978b9450f1a8871dbfa538a2b824d289a7a8c234
parente2cd0ad08fdb756f251e3def4a4277d22ba54728 (diff)
downloadlua-language-server-4e52738f7a315085505ffdbefe9ce6722ec3965f.zip
暂存
-rw-r--r--meta/template/file.lua8
-rw-r--r--meta/template/io.lua70
-rw-r--r--meta/template/math.lua149
-rw-r--r--meta/template/os.lua60
-rw-r--r--meta/template/package.lua25
-rw-r--r--meta/template/string.lua0
-rw-r--r--script-beta/core/completion.lua11
-rw-r--r--test-beta/completion/init.lua8
8 files changed, 315 insertions, 16 deletions
diff --git a/meta/template/file.lua b/meta/template/file.lua
index 8dd97cbc..f24c0a38 100644
--- a/meta/template/file.lua
+++ b/meta/template/file.lua
@@ -7,9 +7,11 @@ local file = {}
---|>'"l"'
---| '"L"'
----@return boolean suc?
----@return '"exit"'|'"signal"'?
----@return integer code?
+---@alias exitcode | '"exit"'|'"signal"'
+
+---@return boolean suc?
+---@return exitcode exitcode?
+---@return integer code?
function file:close() end
function file:flush() end
diff --git a/meta/template/io.lua b/meta/template/io.lua
new file mode 100644
index 00000000..c0d1689c
--- /dev/null
+++ b/meta/template/io.lua
@@ -0,0 +1,70 @@
+---@class io
+---@field stdin file
+---@field stdout file
+---@field stderr file
+io = {}
+
+---@alias openmode
+---|>'"r"'
+---| '"w"'
+---| '"a"'
+---| '"r+"'
+---| '"w+"'
+---| '"a+"'
+---| '"rb"'
+---| '"wb"'
+---| '"ab"'
+---| '"r+b"'
+---| '"w+b"'
+---| '"a+b"'
+
+---@param file file?
+---@return boolean suc?
+---@return exitcode exitcode?
+---@return integer code?
+function io.close(file) end
+
+function io.flush() end
+
+---@overload fun():file
+---@param file string|file
+function io.input(file) end
+
+---@param filename string?
+---@vararg readmode
+---@return fun():string|number
+function io.lines(filename, ...) end
+
+---@overload fun():file
+---@param file string|file
+function io.output(file) end
+
+---@alias popenmode
+---| '"r"'
+---| '"w"'
+
+---@param prog string
+---@param mode popenmode?
+---@return file?
+---@return string errmsg?
+function io.popen(prog, mode) end
+
+---@vararg readmode
+---@return string|number
+---@return ...
+function io.read(...) end
+
+---@return file
+function io.tmpfile() end
+
+---@alias filetype
+---| '"file"'
+---| '"closed file"'
+---| 'nil'
+---@param file file
+---@return filetype
+function io.type(file) end
+
+---@return file
+---@return string errmsg?
+function io.write(...) end
diff --git a/meta/template/math.lua b/meta/template/math.lua
new file mode 100644
index 00000000..31473b25
--- /dev/null
+++ b/meta/template/math.lua
@@ -0,0 +1,149 @@
+---@class math
+---@field huge number
+---@field maxinteger integer
+---@field mininteger integer
+---@field pi number
+math = {}
+
+---@param x number
+---@return number
+function math.abs(x) end
+
+---@param x number
+---@return number
+function math.acos(x) end
+
+---@param x number
+---@return number
+function math.asin(x) end
+
+---@param y number
+---@param x number
+---@return number
+function math.atan(y, x) end
+
+---@param y number
+---@param x number
+---@return number
+
+---@param y any
+---@param x any
+function math.atan2(y, x) end
+
+---@param x number
+---@return integer
+function math.ceil(x) end
+
+---@param x number
+function math.cos(x) end
+
+---@param x number
+---@return number
+function math.cosh(x) end
+
+---@param x number
+---@return number
+function math.deg(x) end
+
+---@param x number
+---@return number
+function math.exp(x) end
+
+---@param x number
+---@return number
+function math.floor(x) end
+
+---@param x number
+---@param y number
+---@return number
+function math.fmod(x, y) end
+
+---@param x number
+---@return number m
+---@return number e
+function math.frexp(x) end
+
+---@param m number
+---@param e number
+---@return number
+function math.ldexp(m, e) end
+
+---@param x number
+---@param base integer?
+---@return number
+function math.log(x, base) end
+
+---@param x number
+---@return number
+function math.log10(x) end
+
+---@param x number
+---@vararg number
+---@return number
+function math.max(x, ...) end
+
+---@param x number
+---@vararg number
+---@return number
+function math.min(x, ...) end
+
+---@param x number
+---@return integer
+---@return number
+function math.modf(x) end
+
+---@param x number
+---@param y number
+---@return number
+function math.pow(x, y) end
+
+---@param x number
+---@return number
+function math.rad(x) end
+
+---@overload fun():number
+---@overload fun(m: integer):integer
+---@param m integer
+---@param n integer
+---@return integer
+function math.random(m, n) end
+
+---@param x integer?
+---@param y integer?
+function math.randomseed(x, y) end
+
+---@param x number
+---@return number
+function math.sin(x) end
+
+---@param x number
+---@return number
+function math.sinh(x) end
+
+---@param x number
+---@return number
+function math.sqrt(x) end
+
+---@param x number
+---@return number
+function math.tan(x) end
+
+---@param x number
+---@return number
+function math.tanh(x) end
+
+---@param x number
+---@return integer?
+function math.tointeger(x) end
+
+---@param x any
+---@return
+---| '"integer"'
+---| '"float"'
+---| 'nil'
+function math.type(x) end
+
+---@param m integer
+---@param n integer
+---@return boolean
+function math.ult(m, n) end
diff --git a/meta/template/os.lua b/meta/template/os.lua
new file mode 100644
index 00000000..d4350721
--- /dev/null
+++ b/meta/template/os.lua
@@ -0,0 +1,60 @@
+---@class os
+os = {}
+
+---@return number
+function os.clock() end
+
+---@param format string?
+---@param time integer?
+---@return string
+function os.date(format, time) end
+
+---@param t2 integer
+---@param t1 integer
+---@return integer
+function os.difftime(t2, t1) end
+
+---@param command string
+---@return boolean suc?
+---@return exitcode exitcode?
+---@return integer code?
+function os.execute(command) end
+
+---@param code boolean|integer?
+---@param close boolean?
+function os.exit(code, close) end
+
+---@param varname string
+---@return string
+function os.getenv(varname) end
+
+---@param filename string
+---@return boolean suc
+---@return string errmsg?
+function os.remove(filename) end
+
+---@param oldname string
+---@param newname string
+---@return boolean suc
+---@return string errmsg?
+function os.rename(oldname, newname) end
+
+---@alias localecategory
+---|>'"all"'
+---| '"collate"'
+---| '"ctype"'
+---| '"monetary"'
+---| '"numeric"'
+---| '"time"'
+
+---@param locale string|nil
+---@param category localecategory?
+---@return string localecategory
+function os.setlocale(locale, category) end
+
+---@param date table?
+---@return integer
+function os.time(date) end
+
+---@return string
+function os.tmpname() end
diff --git a/meta/template/package.lua b/meta/template/package.lua
new file mode 100644
index 00000000..7970e2ca
--- /dev/null
+++ b/meta/template/package.lua
@@ -0,0 +1,25 @@
+---@class package
+---@field conifg string
+---@field cpath string
+---@field loaded table
+---@field loaders table
+---@field path string
+---@field preload table
+---@field searchers table
+package = {}
+
+---@param libname string
+---@param funcname string
+---@return any
+function package.loadlib(libname, funcname) end
+
+---@param name string
+---@param path string
+---@param sep string?
+---@param rep string?
+---@return string|nil filename
+---@return string errmsg?
+function package.searchpath(name, path, sep, rep) end
+
+---@param module table
+function package.seeall(module) end
diff --git a/meta/template/string.lua b/meta/template/string.lua
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/meta/template/string.lua
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 67dc9af2..02c6673c 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -1176,20 +1176,13 @@ local function tryLuaDocByErr(ast, offset, err, docState, results)
end
local label = {}
local insertText = {}
- local max = 0
- for _, arg in ipairs(func.args) do
- if arg[1] then
- max = max + 1
- end
- end
for i, arg in ipairs(func.args) do
if arg[1] then
label[#label+1] = arg[1]
- local index = i == max and 0 or i
if i == 1 then
- insertText[i] = ('%s ${%d:any}'):format(arg[1], index)
+ insertText[i] = ('%s ${%d:any}'):format(arg[1], i)
else
- insertText[i] = ('---@param %s ${%d:any}'):format(arg[1], index)
+ insertText[i] = ('---@param %s ${%d:any}'):format(arg[1], i)
end
end
end
diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua
index 0d1db3fe..2fc1a913 100644
--- a/test-beta/completion/init.lua
+++ b/test-beta/completion/init.lua
@@ -1298,7 +1298,7 @@ end
insertText = [[
a ${1:any}
---@param b ${2:any}
----@param c ${0:any}]]
+---@param c ${3:any}]]
},
{
label = 'a',
@@ -1327,7 +1327,7 @@ function f2(a) end
insertText = [[
a ${1:any}
---@param b ${2:any}
----@param c ${0:any}]]
+---@param c ${3:any}]]
},
{
label = 'a',
@@ -1369,7 +1369,7 @@ end
insertText = [[
a ${1:any}
---@param b ${2:any}
----@param c ${0:any}]]
+---@param c ${3:any}]]
},
{
label = 'a',
@@ -1397,7 +1397,7 @@ end
insertText = [[
a ${1:any}
---@param b ${2:any}
----@param c ${0:any}]]
+---@param c ${3:any}]]
},
{
label = 'a',