@@ -3,12 +3,13 @@ local ssub = require 'core.substring'
3
3
local guide = require ' parser.guide'
4
4
local _M = {}
5
5
6
- function _M .buildComment (t , value )
6
+ function _M .buildComment (t , value , pos )
7
7
return {
8
- type = ' comment.short' ,
9
- start = 1 ,
10
- finish = 1 ,
11
- text = " -@" .. t .. " " .. value ,
8
+ type = ' comment.short' ,
9
+ start = pos ,
10
+ finish = pos ,
11
+ text = " -@" .. t .. " " .. value ,
12
+ virtual = true
12
13
}
13
14
end
14
15
@@ -28,10 +29,7 @@ function _M.addClassDoc(ast, source, classname)
28
29
end
29
30
-- TODO fileds
30
31
-- TODO callers
31
- local comment = _M .buildComment (" class" , classname )
32
- comment .start = source .start - 1
33
- comment .finish = comment .start
34
-
32
+ local comment = _M .buildComment (" class" , classname , source .start - 1 )
35
33
return luadoc .buildAndBindDoc (ast , source , comment )
36
34
end
37
35
40
38
--- @param index integer
41
39
--- @return parser.object ?
42
40
function _M .removeArg (source , index )
43
- if source .type == ' function' then
41
+ if source .type == ' function' or source . type == ' call ' then
44
42
local arg = table.remove (source .args , index )
45
43
if not arg then
46
44
return nil
@@ -51,16 +49,36 @@ function _M.removeArg(source, index)
51
49
return nil
52
50
end
53
51
54
- --- 把特定函数当成构造函数,`index` 参数是self
52
+ --- 把特定函数当成构造函数,`index` 参数是self
55
53
--- @param classname string
56
54
--- @param source parser.object function node
57
55
--- @param index integer
56
+ --- @return boolean , parser.object ?
58
57
function _M .addClassDocAtParam (ast , classname , source , index )
59
58
local arg = _M .removeArg (source , index )
60
59
if arg then
61
- return _M .addClassDoc (ast , arg , classname )
60
+ return _M .addClassDoc (ast , arg , classname ), arg
62
61
end
63
62
return false
64
63
end
65
64
65
+ --- 把函数参数绑定类型
66
+ --- @param ast parser.object
67
+ --- @param typename string
68
+ --- @param source parser.object
69
+ function _M .addParamTypeDoc (ast , typename , source )
70
+ if not guide .isParam (source ) then
71
+ return false
72
+ end
73
+ local paramname = guide .getKeyName (source )
74
+ if not paramname then
75
+ return false
76
+ end
77
+ local comment = _M .buildComment (" param" ,
78
+ (' %s %s' ):format (paramname , typename ),
79
+ source .start - 1 )
80
+
81
+ return luadoc .buildAndBindDoc (ast , source .parent .parent , comment )
82
+ end
83
+
66
84
return _M
0 commit comments