From 266cc7b0c30194300ca49eda6da95941b01474b9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Jan 2012 22:24:29 -0800 Subject: [PATCH] rustdoc: Add fn arg descriptions to the doc tree --- src/rustdoc/attr_pass.rs | 30 ++++++++++++++++++++++++++---- src/rustdoc/doc.rs | 1 + src/rustdoc/extract.rs | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index 8a0983296a8..a804a836248 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -154,11 +154,23 @@ fn merge_fn_attrs( } fn merge_arg_attrs( - doc: [doc::argdoc], - _attrs: [attr_parser::arg_attrs] + docs: [doc::argdoc], + attrs: [attr_parser::arg_attrs] ) -> [doc::argdoc] { - // FIXME - doc + vec::map(docs) {|doc| + alt vec::find(attrs) {|attr| + attr.name == doc.name + } { + some(attr) { + ~{ + desc: some(attr.desc) + with *doc + } + } + none. { doc } + } + } + // FIXME: Warning when documenting a non-existant arg } fn merge_ret_attrs( @@ -179,3 +191,13 @@ fn fold_fn_should_extract_fn_attributes() { let doc = fold_fn(fold, doc.topmod.fns[0]); assert doc.desc == some("test"); } + +#[test] +fn fold_fn_should_extract_arg_attributes() { + let source = "#[doc(args(a = \"b\"))] fn c(a: bool) { }"; + let srv = astsrv::mk_srv_from_str(source); + let doc = extract::from_srv(srv, ""); + let fold = fold::default_seq_fold(srv); + let doc = fold_fn(fold, doc.topmod.fns[0]); + assert doc.args[0].desc == some("b"); +} \ No newline at end of file diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index c084bfe2657..d811eaf13c6 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -26,6 +26,7 @@ type argdoc = ~{ name: str, + desc: option, ty: option }; diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index 68eeb419f1a..08f437a44c0 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -100,6 +100,7 @@ fn argdocs_from_args(args: [ast::arg]) -> [doc::argdoc] { fn argdoc_from_arg(arg: ast::arg) -> doc::argdoc { ~{ name: arg.ident, + desc: none, ty: none } }