rustdoc: Add fn arg descriptions to the doc tree

This commit is contained in:
Brian Anderson 2012-01-18 22:24:29 -08:00
parent 515fdb2863
commit 266cc7b0c3
3 changed files with 28 additions and 4 deletions

View File

@ -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");
}

View File

@ -26,6 +26,7 @@
type argdoc = ~{
name: str,
desc: option<str>,
ty: option<str>
};

View File

@ -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
}
}