rustdoc: Assign AST ids to mod docs

This commit is contained in:
Brian Anderson 2012-01-18 18:35:55 -08:00
parent 5bbf72e11c
commit e39e34776e
4 changed files with 17 additions and 4 deletions

View file

@ -7,6 +7,7 @@ type cratedoc = ~{
};
type moddoc = ~{
id: ast_id,
name: str,
brief: option<str>,
desc: option<str>,

View file

@ -29,14 +29,16 @@ fn top_moddoc_from_crate(
crate: @ast::crate,
default_name: str
) -> doc::moddoc {
moddoc_from_mod(crate.node.module, default_name)
moddoc_from_mod(crate.node.module, default_name, ast::crate_node_id)
}
fn moddoc_from_mod(
module: ast::_mod,
name: ast::ident
name: ast::ident,
id: ast::node_id
) -> doc::moddoc {
~{
id: id,
name: name,
brief: none,
desc: none,
@ -44,7 +46,7 @@ fn moddoc_from_mod(
vec::filter_map(module.items) {|item|
alt item.node {
ast::item_mod(m) {
some(moddoc_from_mod(m, item.ident))
some(moddoc_from_mod(m, item.ident, item.id))
}
_ {
none
@ -133,6 +135,14 @@ mod tests {
assert doc.topmod.mods[0].mods[0].mods[0].name == "c";
}
#[test]
fn extract_should_set_mod_ast_id() {
let source = "mod a { }";
let ast = parse::from_str(source);
let doc = extract(ast, "");
assert doc.topmod.mods[0].id != 0;
}
#[test]
fn extract_fns() {
let source =

View file

@ -11,7 +11,7 @@ fn new_parse_sess() -> parser::parse_sess {
let cm = codemap::new_codemap();
let sess = @{
cm: cm,
mutable next_id: 0,
mutable next_id: 1,
diagnostic: diagnostic::mk_handler(cm, none)
};
ret sess;

View file

@ -26,6 +26,7 @@ fn test_run_passes() {
) -> doc::cratedoc {
~{
topmod: ~{
id: 0,
name: doc.topmod.name + "two",
brief: none,
desc: none,
@ -40,6 +41,7 @@ fn test_run_passes() {
) -> doc::cratedoc {
~{
topmod: ~{
id: 0,
name: doc.topmod.name + "three",
brief: none,
desc: none,