File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ mod attr_parser;
18
18
mod doc;
19
19
mod gen;
20
20
mod fold;
21
+ mod path_pass;
21
22
mod attr_pass;
22
23
mod tystr_pass;
23
24
mod prune_undoc_pass;
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ fn run(source_file: str) {
93
93
let doc = extract:: from_srv ( srv, default_name) ;
94
94
run_passes ( srv, doc, [
95
95
attr_pass:: mk_pass ( ) ,
96
+ path_pass:: mk_pass ( ) ,
96
97
// FIXME: This pass should be optional
97
98
prune_undoc_pass:: mk_pass ( ) ,
98
99
tystr_pass:: mk_pass ( ) ,
You can’t perform that action at this time.
0 commit comments