Skip to content

Commit 181e93f

Browse files
authored
Merge pull request #2186 from AlWoSp/pr/adapt-incomplete-signature-doc
Adapt incomplete-signature-doc to warn about incomplete, not missing docs
2 parents 1454649 + 8a884c3 commit 181e93f

File tree

2 files changed

+135
-15
lines changed

2 files changed

+135
-15
lines changed

script/core/diagnostics/incomplete-signature-doc.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ local function findReturn(docs, index)
3838
return false
3939
end
4040

41+
--- check if there's any signature doc (@param or @return), or just comments, @async, ...
42+
local function findSignatureDoc(docs)
43+
if not docs then
44+
return false
45+
end
46+
for _, doc in ipairs(docs) do
47+
if doc.type == 'doc.return' or doc.type == 'doc.param' then
48+
return true
49+
end
50+
end
51+
return false
52+
end
53+
4154
---@async
4255
return function (uri, callback)
4356
local state = files.getState(uri)
@@ -59,6 +72,12 @@ return function (uri, callback)
5972

6073
local functionName = source.parent[1]
6174

75+
--- don't apply rule if there is no @param or @return annotation yet
76+
--- so comments and @async can be applied without the need for a full documentation
77+
if(not findSignatureDoc(source.bindDocs)) then
78+
return
79+
end
80+
6281
if source.args and #source.args > 0 then
6382
for _, arg in ipairs(source.args) do
6483
local argName = arg[1]

test/diagnostics/incomplete-signature-doc.lua

Lines changed: 116 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,50 @@ config.set(nil, 'Lua.diagnostics.neededFileStatus',
2525
['incomplete-signature-doc'] = 'Any!' -- override groupFileStatus
2626
})
2727

28-
-- check global functions
28+
-- -------------------------------------
29+
-- about the structure of these test cases
30+
--
31+
-- the following test cases are grouped by the number of parameters and return values of the functions
32+
-- so first global functions with:
33+
-- no parameter and return value (FG), one parameter (FGP), two parameters (FGPP),
34+
-- one return value (FGR), two return values (FGRR) and parameter and return value (FGPR)
35+
-- after that, these groups are also done for local functions (FL, FLP, ...)
36+
--
37+
-- in these groups, different versions of documentation are tested:
38+
-- no comment, simple comment, @async annotation (which is no signature doc),
39+
-- incomplete signature doc (only part of the necessary @param or @return annotations, if possible) - the only cases that should generating warnings
40+
-- and complete signature docs (all necessary @param and @return annotations)
41+
-- -------------------------------------
42+
43+
-- global functions no parameter, no return value
44+
-- no incomplete signature docs possible
2945
TEST [[
3046
function FG0()
3147
end
3248
3349
---comment
3450
function FG1()
3551
end
52+
53+
---@async
54+
function FG1_()
55+
end
3656
]]
3757

58+
-- global functions with single parameter, no return value
59+
-- no incomplete signature docs possible
3860
TEST [[
3961
function FGP0(p)
4062
print(p)
4163
end
4264
4365
---comment
44-
function FGP1(<!p!>)
66+
function FGP1(p)
67+
print(p)
68+
end
69+
70+
---@async
71+
function FGP1_(p)
4572
print(p)
4673
end
4774
@@ -52,13 +79,20 @@ function FGP2(p)
5279
end
5380
]]
5481

82+
-- global functions with two parameters, no return value
83+
-- incomplete signature docs when exactly one of the parameters is documented
5584
TEST [[
5685
function FGPP0(p0, p1)
5786
print(p0, p1)
5887
end
5988
6089
---comment
61-
function FGPP1(<!p0!>, <!p1!>)
90+
function FGPP1(p0, p1)
91+
print(p0, p1)
92+
end
93+
94+
---@async
95+
function FGPP1_(p0, p1)
6296
print(p0, p1)
6397
end
6498
@@ -68,6 +102,12 @@ function FGPP2(p0, <!p1!>)
68102
print(p0, p1)
69103
end
70104
105+
---comment
106+
---@param p1 any
107+
function FGPP2_(<!p0!>, p1)
108+
print(p0, p1)
109+
end
110+
71111
---comment
72112
---@param p0 any
73113
---@param p1 any
@@ -76,14 +116,21 @@ function FGPP3(p0, p1)
76116
end
77117
]]
78118

119+
-- global functions with no parameter, single return value
120+
-- no incomplete signature docs possible
79121
TEST [[
80122
function FGR0()
81123
return 0
82124
end
83125
84126
---comment
85127
function FGR1()
86-
return <!0!>
128+
return 0
129+
end
130+
131+
---@async
132+
function FGR1_()
133+
return 0
87134
end
88135
89136
---comment
@@ -93,14 +140,21 @@ function FGR2()
93140
end
94141
]]
95142

143+
-- global functions with no parameter, two return values
144+
-- incomplete signature docs when exactly one of the return values is documented
96145
TEST [[
97146
function FGRR0()
98147
return 0, 1
99148
end
100149
101150
---comment
102151
function FGRR1()
103-
return <!0!>, <!1!>
152+
return 0, 1
153+
end
154+
155+
---@async
156+
function FGRR1_()
157+
return 0, 1
104158
end
105159
106160
---comment
@@ -117,16 +171,24 @@ function FGRR3()
117171
end
118172
]]
119173

174+
-- global functions with one parameter, one return value
175+
-- incomplete signature docs when exactly one of parameter or return value is documented
120176
TEST [[
121177
function FGPR0(p)
122178
print(p)
123179
return 0
124180
end
125181
126182
---comment
127-
function FGPR1(<!p!>)
183+
function FGPR1(p)
128184
print(p)
129-
return <!0!>
185+
return 0
186+
end
187+
188+
---@async
189+
function FGPR1_(p)
190+
print(p)
191+
return 0
130192
end
131193
132194
---comment
@@ -152,8 +214,8 @@ function FGPR4(p)
152214
end
153215
]]
154216

155-
-- check local functions
156-
217+
-- local functions with no parameter, no return value
218+
-- no incomplete signature docs possible
157219
TEST [[
158220
local function FL0()
159221
end
@@ -165,8 +227,13 @@ local function FL1()
165227
end
166228
167229
FL1()
230+
231+
---@async
232+
local function FL1_()
168233
]]
169234

235+
-- local functions with single parameter, no return value
236+
-- no incomplete signature docs possible
170237
TEST [[
171238
local function FLP0(p)
172239
print(p)
@@ -175,12 +242,17 @@ end
175242
FLP0(0)
176243
177244
---comment
178-
local function FLP1(<!p!>)
245+
local function FLP1(p)
179246
print(p)
180247
end
181248
182249
FLP1(0)
183250
251+
---@async
252+
local function FLP1_(p)
253+
print(p)
254+
end
255+
184256
---comment
185257
---@param p any
186258
local function FLP2(p)
@@ -190,6 +262,8 @@ end
190262
FLP2(0)
191263
]]
192264

265+
-- local functions with two parameters, no return value
266+
-- incomplete signature docs when exactly one of the parameters is documented
193267
TEST [[
194268
local function FLPP0(p0, p1)
195269
print(p0, p1)
@@ -198,12 +272,17 @@ end
198272
FLPP0(0, 1)
199273
200274
---comment
201-
local function FLPP1(<!p0!>, <!p1!>)
275+
local function FLPP1(p0, p1)
202276
print(p0, p1)
203277
end
204278
205279
FLPP1(0, 1)
206280
281+
---@async
282+
local function FLPP1_(p0, p1)
283+
print(p0, p1)
284+
end
285+
207286
---comment
208287
---@param p0 any
209288
local function FLPP2(p0, <!p1!>)
@@ -222,6 +301,8 @@ end
222301
FLPP3(0, 1)
223302
]]
224303

304+
-- local functions with no parameter, single return value
305+
-- no incomplete signature docs possible
225306
TEST [[
226307
local function FLR0()
227308
return 0
@@ -231,7 +312,12 @@ local vr0 = FLR0()
231312
232313
---comment
233314
local function FLR1()
234-
return <!0!>
315+
return 0
316+
end
317+
318+
---@async
319+
local function FLR1_()
320+
return 0
235321
end
236322
237323
local vr1 = FLR1()
@@ -245,6 +331,8 @@ end
245331
local vr2 = FLR2()
246332
]]
247333

334+
-- local functions with no parameter, two return values
335+
-- incomplete signature docs when exactly one of the return values is documented
248336
TEST [[
249337
local function FLRR0()
250338
return 0, 1
@@ -254,11 +342,16 @@ local vrr0, _ = FLRR0()
254342
255343
---comment
256344
local function FLRR1()
257-
return <!0!>, <!1!>
345+
return 0, 1
258346
end
259347
260348
local vrr1, _ = FLRR1()
261349
350+
---@async
351+
local function FLRR1_()
352+
return 0, 1
353+
end
354+
262355
---comment
263356
---@return integer
264357
local function FLRR2()
@@ -277,6 +370,8 @@ end
277370
local vrr3, _ = FLRR3()
278371
]]
279372

373+
-- local functions with one parameter, one return value
374+
-- incomplete signature docs when exactly one of parameter or return value is documented
280375
TEST [[
281376
local function FLPR0(p)
282377
print(p)
@@ -286,9 +381,15 @@ end
286381
local vpr0 = FLPR0(0)
287382
288383
---comment
289-
local function FLPR1(<!p!>)
384+
local function FLPR1(p)
290385
print(p)
291-
return <!0!>
386+
return 0
387+
end
388+
389+
---@async
390+
local function FLPR1_(p)
391+
print(p)
392+
return 0
292393
end
293394
294395
local vpr1 = FLPR1(0)

0 commit comments

Comments
 (0)