Skip to content

Commit 05b8cf4

Browse files
committed
fix #1223 count returns of doc.type.function
1 parent 6a9e89a commit 05b8cf4

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* `FIX` [#1217](https://github.com/sumneko/lua-language-server/issues/1217)
77
* `FIX` [#1218](https://github.com/sumneko/lua-language-server/issues/1218)
88
* `FIX` [#1220](https://github.com/sumneko/lua-language-server/issues/1220)
9+
* `FIX` [#1223](https://github.com/sumneko/lua-language-server/issues/1223)
910

1011
## 3.3.0
1112
`2022-6-15`

script/core/diagnostics/missing-parameter.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local lang = require 'language'
55

66
---@param source parser.object
77
---@return integer
8-
local function countReturns(source)
8+
local function countReturnsOfFunction(source)
99
local n = 0
1010

1111
local docs = source.bindDocs
@@ -33,14 +33,25 @@ local function countReturns(source)
3333
return n
3434
end
3535

36+
---@param source parser.object
37+
---@return integer
38+
local function countReturnsOfDocFunction(source)
39+
return #source.returns
40+
end
41+
3642
local function countMaxReturns(source)
3743
local hasFounded
3844
local n = 0
3945
for _, def in ipairs(vm.getDefs(source)) do
40-
if def.type == 'doc.type.function'
41-
or def.type == 'function' then
46+
if def.type == 'function' then
47+
hasFounded = true
48+
local rets = countReturnsOfFunction(def)
49+
if rets > n then
50+
n = rets
51+
end
52+
elseif def.type == 'doc.type.function' then
4253
hasFounded = true
43-
local rets = countReturns(def)
54+
local rets = countReturnsOfDocFunction(def)
4455
if rets > n then
4556
n = rets
4657
end

test/diagnostics/common.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,3 +1601,15 @@ end
16011601
16021602
f1(f2())
16031603
]]
1604+
1605+
TEST [[
1606+
---@meta
1607+
1608+
---@type fun():integer
1609+
local f
1610+
1611+
---@param x integer
1612+
local function foo(x) end
1613+
1614+
foo(f())
1615+
]]

0 commit comments

Comments
 (0)