Skip to content

Commit f0f80fd

Browse files
committed
fix #1131
1 parent c1e9e46 commit f0f80fd

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

Diff for: changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.2.4
44
* `FIX` hover: can not union `table` with other basic types
55
* `FIX` [#1125](https://github.com/sumneko/lua-language-server/issues/1125)
6+
* `FIX` [#1131](https://github.com/sumneko/lua-language-server/issues/1131)
67

78
## 3.2.3
89
`2022-5-16`

Diff for: script/core/diagnostics/missing-parameter.lua

+58
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,69 @@ local guide = require 'parser.guide'
33
local vm = require 'vm'
44
local lang = require 'language'
55

6+
---@param source parser.object
7+
---@return integer
8+
local function countReturns(source)
9+
local n = 0
10+
11+
local docs = source.bindDocs
12+
if docs then
13+
for _, doc in ipairs(docs) do
14+
if doc.type == 'doc.return' then
15+
for _, rtn in ipairs(doc.returns) do
16+
if rtn.returnIndex and rtn.returnIndex > n then
17+
n = rtn.returnIndex
18+
end
19+
end
20+
end
21+
end
22+
end
23+
24+
local returns = source.returns
25+
if returns then
26+
for _, rtn in ipairs(returns) do
27+
if #rtn > n then
28+
n = #rtn
29+
end
30+
end
31+
end
32+
33+
return n
34+
end
35+
36+
local function countMaxReturns(source)
37+
local hasFounded
38+
local n = 0
39+
for _, def in ipairs(vm.getDefs(source)) do
40+
if def.type == 'doc.type.function'
41+
or def.type == 'function' then
42+
hasFounded = true
43+
local rets = countReturns(def)
44+
if rets > n then
45+
n = rets
46+
end
47+
end
48+
end
49+
50+
if hasFounded then
51+
return n
52+
else
53+
return math.huge
54+
end
55+
end
56+
657
local function countCallArgs(source)
758
local result = 0
859
if not source.args then
960
return 0
1061
end
62+
local lastArg = source.args[#source.args]
63+
if lastArg.type == 'varargs' then
64+
return math.huge
65+
end
66+
if lastArg.type == 'call' then
67+
result = result + countMaxReturns(lastArg) - 1
68+
end
1169
result = result + #source.args
1270
return result
1371
end

Diff for: test/diagnostics/common.lua

+26
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,32 @@ end
282282
x(1, 2)
283283
]]
284284

285+
TEST [[
286+
---@diagnostic disable: unused-local
287+
288+
---@param a integer
289+
---@param b integer
290+
local function f(a, b)
291+
end
292+
293+
f(...)
294+
]]
295+
296+
TEST [[
297+
---@diagnostic disable: unused-local
298+
299+
---@param a integer
300+
---@param b integer
301+
local function f(a, b)
302+
end
303+
304+
local function return2Numbers()
305+
return 1, 2
306+
end
307+
308+
f(return2Numbers())
309+
]]
310+
285311
TEST [[
286312
---@param a integer
287313
---@param b? integer

0 commit comments

Comments
 (0)