summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-23 00:42:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-23 00:42:10 +0800
commitec1f746a71dfb981f093bf00322db75d559fd6b6 (patch)
tree71730d2de455bf7cd8a9481a554a56cddf47f341
parent6e00db5b51646ad91c5ee5598897cad7f8d65915 (diff)
downloadlua-language-server-ec1f746a71dfb981f093bf00322db75d559fd6b6.zip
fix optional parameters
-rw-r--r--meta/template/io.lua4
-rw-r--r--meta/template/string.lua2
-rw-r--r--meta/template/table.lua2
-rw-r--r--script/client.lua2
-rw-r--r--script/core/diagnostics/init.lua2
-rw-r--r--script/core/diagnostics/missing-parameter.lua11
-rw-r--r--script/core/look-backward.lua7
-rw-r--r--script/core/matchkey.lua2
-rw-r--r--script/encoder/init.lua12
-rw-r--r--script/files.lua4
-rw-r--r--script/glob/gitignore.lua2
-rw-r--r--script/pub/pub.lua2
-rw-r--r--script/utility.lua8
-rw-r--r--script/vm/node.lua6
-rw-r--r--script/vm/ref.lua2
-rw-r--r--script/workspace/loading.lua2
-rw-r--r--test/diagnostics/common.lua13
17 files changed, 47 insertions, 36 deletions
diff --git a/meta/template/io.lua b/meta/template/io.lua
index b2846878..b1fe5a9e 100644
--- a/meta/template/io.lua
+++ b/meta/template/io.lua
@@ -47,7 +47,7 @@ function io.lines(filename, ...) end
---#DES 'io.open'
---@param filename string
----@param mode openmode
+---@param mode? openmode
---@return file*?
---@return string? errmsg
---@nodiscard
@@ -157,7 +157,7 @@ function file:seek(whence, offset) end
---#DES 'file:setvbuf'
---@param mode vbuf
----@param size integer
+---@param size? integer
function file:setvbuf(mode, size) end
---#DES 'file:write'
diff --git a/meta/template/string.lua b/meta/template/string.lua
index 0e0d0537..a115648e 100644
--- a/meta/template/string.lua
+++ b/meta/template/string.lua
@@ -65,7 +65,7 @@ function string.gmatch(s, pattern, init) end
---@param s string
---@param pattern string
---@param repl string|table|function
----@param n integer
+---@param n? integer
---@return string
---@return integer count
---@nodiscard
diff --git a/meta/template/table.lua b/meta/template/table.lua
index 02288342..a7fe68d2 100644
--- a/meta/template/table.lua
+++ b/meta/template/table.lua
@@ -52,7 +52,7 @@ function table.remove(list, pos) end
---#DES 'table.sort'
---@generic T
---@param list T[]
----@param comp fun(a: T, b: T):boolean
+---@param comp? fun(a: T, b: T):boolean
function table.sort(list, comp) end
---@version >5.2, JIT
diff --git a/script/client.lua b/script/client.lua
index daa9bc52..82a01256 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -318,7 +318,7 @@ local function tryModifyClientGlobal(finalChanges)
end
---@param changes config.change[]
----@param onlyMemory boolean
+---@param onlyMemory? boolean
function m.setConfig(changes, onlyMemory)
local finalChanges = {}
for _, change in ipairs(changes) do
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 369a6ba2..b4ae3715 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -105,7 +105,7 @@ end
---@param uri uri
---@param isScopeDiag boolean
---@param response async fun(result: any)
----@param checked async fun(name: string)
+---@param checked? async fun(name: string)
return function (uri, isScopeDiag, response, checked)
local ast = files.getState(uri)
if not ast then
diff --git a/script/core/diagnostics/missing-parameter.lua b/script/core/diagnostics/missing-parameter.lua
index 34cbdab6..e2cf4982 100644
--- a/script/core/diagnostics/missing-parameter.lua
+++ b/script/core/diagnostics/missing-parameter.lua
@@ -69,16 +69,7 @@ return function (uri, callback)
callback {
start = source.start,
finish = source.finish,
+ message = lang.script('DIAG_MISS_ARGS', funcArgs, callArgs),
}
- for i = #source.args - delta + 1, #source.args do
- local arg = source.args[i]
- if arg then
- callback {
- start = arg.start,
- finish = arg.finish,
- message = lang.script('DIAG_MISS_ARGS', funcArgs, callArgs)
- }
- end
- end
end)
end
diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua
index eea089bc..eeee6017 100644
--- a/script/core/look-backward.lua
+++ b/script/core/look-backward.lua
@@ -2,7 +2,8 @@
local m = {}
--- 是否是空白符
----@param inline boolean # 必须在同一行中(排除换行符)
+---@param char string
+---@param inline? boolean # 必须在同一行中(排除换行符)
function m.isSpace(char, inline)
if inline then
if char == ' '
@@ -21,7 +22,9 @@ function m.isSpace(char, inline)
end
--- 跳过空白符
----@param inline boolean # 必须在同一行中(排除换行符)
+---@param text string
+---@param offset integer
+---@param inline? boolean # 必须在同一行中(排除换行符)
function m.skipSpace(text, offset, inline)
for i = offset, 1, -1 do
local char = text:sub(i, i)
diff --git a/script/core/matchkey.lua b/script/core/matchkey.lua
index 3c6a54a8..4db9d764 100644
--- a/script/core/matchkey.lua
+++ b/script/core/matchkey.lua
@@ -59,7 +59,7 @@ end
---@param input string
---@param other string
----@param fast boolean
+---@param fast? boolean
---@return boolean isMatch
---@return number deviation
return function (input, other, fast)
diff --git a/script/encoder/init.lua b/script/encoder/init.lua
index 0011265a..3c8a58e0 100644
--- a/script/encoder/init.lua
+++ b/script/encoder/init.lua
@@ -10,9 +10,9 @@ local utf16be = utf16('be', utf8.codepoint '�')
local m = {}
---@param encoding encoder.encoding
----@param s string
----@param i integer
----@param j integer
+---@param s string
+---@param i? integer
+---@param j? integer
function m.len(encoding, s, i, j)
i = i or 1
j = j or #s
@@ -33,9 +33,9 @@ function m.len(encoding, s, i, j)
end
---@param encoding encoder.encoding
----@param s string
----@param n integer
----@param i integer
+---@param s string
+---@param n integer
+---@param i? integer
function m.offset(encoding, s, n, i)
i = i or 1
if encoding == 'utf16'
diff --git a/script/files.lua b/script/files.lua
index d16474fd..22c9ae31 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -165,8 +165,8 @@ end
--- 设置文件文本
---@param uri uri
---@param text string
----@param isTrust boolean
----@param callback function
+---@param isTrust? boolean
+---@param callback? function
function m.setText(uri, text, isTrust, callback)
if not text then
return
diff --git a/script/glob/gitignore.lua b/script/glob/gitignore.lua
index 09be1415..4dad2747 100644
--- a/script/glob/gitignore.lua
+++ b/script/glob/gitignore.lua
@@ -163,7 +163,7 @@ function mt:getRelativePath(path)
return path
end
----@param callback async fun()
+---@param callback async fun(path: string)
---@async
function mt:scan(path, callback)
local files = {}
diff --git a/script/pub/pub.lua b/script/pub/pub.lua
index e73aea51..47591ee6 100644
--- a/script/pub/pub.lua
+++ b/script/pub/pub.lua
@@ -124,7 +124,7 @@ end
--- 通过 jumpQueue 可以插队
---@param name string
---@param params any
----@param callback function
+---@param callback? function
function m.task(name, params, callback)
local info = {
id = counter(),
diff --git a/script/utility.lua b/script/utility.lua
index 5a52e417..f5cc0e1d 100644
--- a/script/utility.lua
+++ b/script/utility.lua
@@ -83,7 +83,7 @@ local m = {}
--- 打印表的结构
---@param tbl table
----@param option table {optional = 'self'}
+---@param option? table
---@return string
function m.dump(tbl, option)
if not option then
@@ -346,8 +346,8 @@ function m.sortPairs(t, sorter)
end
--- 深拷贝(不处理元表)
----@param source table
----@param target table {optional = 'self'}
+---@param source table
+---@param target? table
function m.deepCopy(source, target)
local mark = {}
local function copy(a, b)
@@ -566,7 +566,7 @@ end
---遍历文本的每一行
---@param text string
----@param keepNL boolean # 保留换行符
+---@param keepNL? boolean # 保留换行符
---@return fun(text:string):string, integer
function m.eachLine(text, keepNL)
local offset = 1
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 92604c3c..b57fa80b 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -100,9 +100,13 @@ function mt:isNullable()
if self.optional then
return true
end
+ if #self == 0 then
+ return true
+ end
for _, c in ipairs(self) do
if c.type == 'nil'
- or (c.type == 'global' and c.cate == 'type' and c.name == 'nil') then
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'any') then
return true
end
end
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index 65e8fdab..29ea27c5 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -291,7 +291,7 @@ end
---@async
---@param source parser.object
----@param fileNotify fun(uri: uri): boolean
+---@param fileNotify? fun(uri: uri): boolean
function vm.getRefs(source, fileNotify)
local results = {}
local mark = {}
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 0e76dcda..66e0a3aa 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -65,7 +65,7 @@ function mt:checkMaxPreload(uri)
end
---@param uri uri
----@param libraryUri uri
+---@param libraryUri? uri
---@async
function mt:loadFile(uri, libraryUri)
if files.isLua(uri) then
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index dc784f28..dca826a1 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -245,10 +245,22 @@ TEST [[
local function x(a, b)
return a, b
end
+x(1)
+]]
+
+TEST [[
+---@param a integer
+---@param b integer
+local function x(a, b)
+ return a, b
+end
<!x(1)!>
]]
TEST [[
+---@param a integer
+---@param b integer
+---@param ... integer
local function x(a, b, ...)
return a, b, ...
end
@@ -256,6 +268,7 @@ x(1, 2)
]]
TEST [[
+---@param a integer
---@param b? integer
local function x(a, b)
return a, b