Skip to content

Commit 3f41fbe

Browse files
committed
---
yaml --- r: 7470 b: refs/heads/master c: a5e0f03 h: refs/heads/master v: v3
1 parent add9ac0 commit 3f41fbe

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c54f53b9d9f67dd4596aac36e59fa6e5d725aaf5
2+
refs/heads/master: a5e0f037be17204c640e2941e576a9dca09efc90

trunk/src/rustdoc/path_pass.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#[doc = "Records the full path to items"];
2+
3+
export mk_pass;
4+
5+
fn mk_pass() -> pass { run }
6+
7+
type ctxt = {
8+
srv: astsrv::srv,
9+
mutable path: [str]
10+
};
11+
12+
fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc {
13+
let ctxt = {
14+
srv: srv,
15+
mutable path: []
16+
};
17+
let fold = fold::fold({
18+
fold_mod: fn~(
19+
f: fold::fold<ctxt>,
20+
d: doc::moddoc
21+
) -> doc::moddoc {
22+
fold_mod(f, d)
23+
}
24+
with *fold::default_seq_fold(ctxt)
25+
});
26+
fold.fold_crate(fold, doc)
27+
}
28+
29+
fn fold_mod(fold: fold::fold<ctxt>, doc: doc::moddoc) -> doc::moddoc {
30+
let is_topmod = doc.id == rustc::syntax::ast::crate_node_id;
31+
32+
if !is_topmod { vec::push(fold.ctxt.path, doc.name); }
33+
let doc = fold::default_seq_fold_mod(fold, doc);
34+
if !is_topmod { vec::pop(fold.ctxt.path); }
35+
~{
36+
path: fold.ctxt.path
37+
with *doc
38+
}
39+
}
40+
41+
#[test]
42+
fn should_record_mod_paths() {
43+
let source = "mod a { mod b { mod c { } } mod d { mod e { } } }";
44+
let srv = astsrv::mk_srv_from_str(source);
45+
let doc = extract::from_srv(srv, "");
46+
let doc = run(srv, doc);
47+
assert doc.topmod.mods[0].mods[0].mods[0].path == ["a", "b"];
48+
assert doc.topmod.mods[0].mods[1].mods[0].path == ["a", "d"];
49+
}

trunk/src/rustdoc/rustdoc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod attr_parser;
1818
mod doc;
1919
mod gen;
2020
mod fold;
21+
mod path_pass;
2122
mod attr_pass;
2223
mod tystr_pass;
2324
mod prune_undoc_pass;

trunk/src/rustdoc/rustdoc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn run(source_file: str) {
9393
let doc = extract::from_srv(srv, default_name);
9494
run_passes(srv, doc, [
9595
attr_pass::mk_pass(),
96+
path_pass::mk_pass(),
9697
// FIXME: This pass should be optional
9798
prune_undoc_pass::mk_pass(),
9899
tystr_pass::mk_pass(),

0 commit comments

Comments
 (0)