Skip to content

Commit 79bf3e6

Browse files
committed
close #135 param comment
1 parent 55b303d commit 79bf3e6

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

script/core/hover/description.lua

+27
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,38 @@ local function tryDocOverloadToComment(source)
198198
end
199199
end
200200

201+
local function tyrDocParamComment(source)
202+
if source.type == 'setlocal'
203+
or source.type == 'getlocal' then
204+
source = source.node
205+
end
206+
if source.type ~= 'local' then
207+
return
208+
end
209+
if source.parent.type ~= 'funcargs' then
210+
return
211+
end
212+
if not source.bindDocs then
213+
return
214+
end
215+
for _, doc in ipairs(source.bindDocs) do
216+
if doc.type == 'doc.param' then
217+
if doc.param[1] == source[1] then
218+
if doc.comment then
219+
return doc.comment.text
220+
end
221+
break
222+
end
223+
end
224+
end
225+
end
226+
201227
return function (source)
202228
if source.type == 'string' then
203229
return asString(source)
204230
end
205231
return tryDocOverloadToComment(source)
206232
or tryDocFieldUpComment(source)
233+
or tyrDocParamComment(source)
207234
or tryDocComment(source)
208235
end

test/crossfile/hover.lua

+5-11
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ function f()
422422
}
423423
}
424424

425-
do return end
426425
TEST {
427426
{
428427
path = 'a.lua',
@@ -431,18 +430,13 @@ TEST {
431430
{
432431
path = 'b.lua',
433432
content = [[
434-
---@param x string {comment = 'aaaa'}
435-
---@param y string {comment = 'bbbb'}
436-
local function <?f?>(x, y) end
433+
---@param x string this is comment
434+
function f(<?x?>) end
437435
]]
438436
},
439437
hover = {
440-
label = 'function f(x: string, y: string)',
441-
name = 'f',
442-
args = EXISTS,
443-
description = [[
444-
+ `x`*(string)*: aaaa
445-
446-
+ `y`*(string)*: bbbb]]
438+
label = 'local x: string',
439+
name = 'x',
440+
description = 'this is comment',
447441
}
448442
}

test/hover/init.lua

-8
Original file line numberDiff line numberDiff line change
@@ -1441,11 +1441,3 @@ local <?y?>
14411441
[[
14421442
local y: any
14431443
]]
1444-
1445-
TEST [[
1446-
---@param x string this is comment
1447-
function f(<?x?>) end
1448-
]]
1449-
[[
1450-
local x: string
1451-
]]

0 commit comments

Comments
 (0)