diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/guide.lua | 19 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 2 | ||||
-rw-r--r-- | script/plugins/astHelper.lua | 40 |
3 files changed, 44 insertions, 17 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 103a8cd5..0d190ed5 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1306,21 +1306,28 @@ function m.isParam(source) end ---@param source parser.object ----@param index integer ----@return parser.object? -function m.getParam(source, index) +---@return parser.object[]? +function m.getParams(source) if source.type == 'call' then local args = source.args assert(args.type == 'callargs', 'call.args type is\'t callargs') - return args[index] + return args elseif source.type == 'callargs' then - return source[index] + return source elseif source.type == 'function' then local args = source.args assert(args.type == 'funcargs', 'function.args type is\'t callargs') - return args[index] + return args end return nil end +---@param source parser.object +---@param index integer +---@return parser.object? +function m.getParam(source, index) + local args = m.getParams(source) + return args and args[index] or nil +end + return m diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index df47fd94..9f3b8fd5 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -2071,6 +2071,7 @@ local function luadoc(state) table.sort(ast.docs, function (a, b) return a.start < b.start end) + ast.state.pluginDocs = nil end ast.docs.start = ast.start @@ -2091,6 +2092,7 @@ return { pluginDocs[#pluginDocs+1] = doc doc.special = src doc.originalComment = comment + doc.virtual = true ast.state.pluginDocs = pluginDocs return true end diff --git a/script/plugins/astHelper.lua b/script/plugins/astHelper.lua index 6f303c79..b12d62c6 100644 --- a/script/plugins/astHelper.lua +++ b/script/plugins/astHelper.lua @@ -3,12 +3,13 @@ local ssub = require 'core.substring' local guide = require 'parser.guide' local _M = {} -function _M.buildComment(t, value) +function _M.buildComment(t, value, pos) return { - type = 'comment.short', - start = 1, - finish = 1, - text = "-@" .. t .. " " .. value, + type = 'comment.short', + start = pos, + finish = pos, + text = "-@" .. t .. " " .. value, + virtual = true } end @@ -28,10 +29,7 @@ function _M.addClassDoc(ast, source, classname) end --TODO fileds --TODO callers - local comment = _M.buildComment("class", classname) - comment.start = source.start - 1 - comment.finish = comment.start - + local comment = _M.buildComment("class", classname, source.start - 1) return luadoc.buildAndBindDoc(ast, source, comment) end @@ -51,16 +49,36 @@ function _M.removeArg(source, index) return nil end ---- 把特定函数当成构造函数,`index` 参数是self +---把特定函数当成构造函数,`index` 参数是self ---@param classname string ---@param source parser.object function node ---@param index integer +---@return boolean, parser.object? function _M.addClassDocAtParam(ast, classname, source, index) local arg = _M.removeArg(source, index) if arg then - return _M.addClassDoc(ast, arg, classname) + return _M.addClassDoc(ast, arg, classname), arg end return false end +---把函数参数绑定类型 +---@param ast parser.object +---@param typename string +---@param source parser.object +function _M.addParamTypeDoc(ast, typename, source) + if not guide.isParam(source) then + return false + end + local paramname = guide.getKeyName(source) + if not paramname then + return false + end + local comment = _M.buildComment("param", + ('%s %s'):format(paramname, typename), + source.start - 1) + + return luadoc.buildAndBindDoc(ast, source, comment) +end + return _M |