summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/diagnostics.lua31
-rw-r--r--server/src/matcher/vm.lua7
-rw-r--r--server/test/diagnostics/init.lua7
3 files changed, 41 insertions, 4 deletions
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua
index 9f3ed7c3..07076b08 100644
--- a/server/src/matcher/diagnostics.lua
+++ b/server/src/matcher/diagnostics.lua
@@ -125,10 +125,28 @@ local function searchNewLineCall(results, lines, callback)
if not call.lastObj.start then
goto NEXT_CALL
end
- local callline = lines:rowcol(call.call.start)
+ local callline = lines:rowcol(call.args.start)
local lastline = lines:rowcol(call.lastObj.finish)
if callline > lastline then
- callback(call.call.start, call.call.finish)
+ callback(call.args.start, call.args.finish)
+ end
+ ::NEXT_CALL::
+ end
+end
+
+local function searchRedundantParameters(results, callback)
+ for _, call in ipairs(results.calls) do
+ if call.func.hasDots then
+ goto NEXT_CALL
+ end
+ if not call.func.args then
+ return
+ end
+ local max = #call.func.args
+ local passed = #call.args
+ for i = max + 1, passed do
+ local source = call.args[i]
+ callback(source.start, source.finish, max, passed)
end
::NEXT_CALL::
end
@@ -192,5 +210,14 @@ return function (vm, lines, uri)
message = 'Parsed as function call for the previous line. It may be necessary to add a `;` before.', -- LOCALE
}
end)
+ -- 调用函数时的参数数量是否超过函数的接收数量
+ searchRedundantParameters(results, function (start, finish, max, passed)
+ datas[#datas+1] = {
+ start = start,
+ finish = finish,
+ level = 'Warning',
+ message = ('The function takes only %d parameters, but you pass %d.'):format(max, passed), -- LOCALE
+ }
+ end)
return datas
end
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index d8cf97ff..aade0f92 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -276,6 +276,7 @@ function mt:buildFunction(exp, object)
func.argValues[#func.args] = self:getValue(var)
elseif arg.type == '...' then
self:createDots(#func.args+1, arg)
+ func.hasDots = true
for _ = 1, 10 do
func.argValues[#func.argValues+1] = self:createValue('any', arg)
end
@@ -701,15 +702,17 @@ function mt:getSimple(simple, mode)
if object then
table.insert(args, 1, self:getValue(object))
end
+ local func = value
-- 函数的返回值一定是list
- value = self:call(value, args)
+ value = self:call(func, args)
if i < #simple then
value = value[1] or self:createValue('any')
end
self.results.calls[#self.results.calls+1] = {
- call = obj,
+ args = obj,
lastObj = simple[i-1],
nextObj = simple[i+1],
+ func = func,
}
parentName = parentName .. '(...)'
elseif obj.index then
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index fc9e8ec3..83725a33 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -119,3 +119,10 @@ TEST [[
print(_G)
('string')
]]
+
+TEST [[
+local function x(a, b)
+ return a, b
+end
+x(1, 2, <!3!>)
+]]