From 38852bf0a4f618c91640e5c90e3871c260cab844 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Jan 2012 14:43:19 -0800 Subject: [PATCH] rustdoc: Extract function argument names from the AST --- src/rustdoc/extract.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index be183e3b0be7..cb6feb98d58a 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -65,7 +65,7 @@ fn moddoc_from_mod( } fn fndoc_from_fn( - _decl: ast::fn_decl, + decl: ast::fn_decl, name: ast::ident, id: ast::node_id ) -> doc::fndoc { @@ -75,10 +75,28 @@ fn fndoc_from_fn( brief: none, desc: none, return: none, - args: [] + args: argdocs_from_args(decl.inputs) } } +#[test] +fn should_extract_fn_args() { + let source = "fn a(b: int, c: int) { }"; + let ast = parse::from_str(source); + let doc = extract(ast, ""); + let fn_ = doc.topmod.fns[0]; + assert tuple::first(fn_.args[0]) == "b"; + assert tuple::first(fn_.args[1]) == "c"; +} + +fn argdocs_from_args(args: [ast::arg]) -> [(str, str)] { + vec::map(args, argdoc_from_arg) +} + +fn argdoc_from_arg(arg: ast::arg) -> (str, str) { + (arg.ident, "") +} + #[cfg(test)] mod tests {