rustdoc: Add the ability to list all passes
In doing so, also remove the collapse-privacy pass because it's a little over-zealous and may not be right 100% of the time (not used right now as well)
This commit is contained in:
parent
bcc7daa6bc
commit
eaaf2bd41f
2 changed files with 45 additions and 34 deletions
|
@ -12,7 +12,6 @@ use std::num;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
use clean;
|
use clean;
|
||||||
use syntax::ast;
|
|
||||||
use clean::Item;
|
use clean::Item;
|
||||||
use plugins;
|
use plugins;
|
||||||
use fold;
|
use fold;
|
||||||
|
@ -69,27 +68,6 @@ pub fn unindent_comments(crate: clean::Crate) -> plugins::PluginResult {
|
||||||
(crate, None)
|
(crate, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collapse_privacy(crate: clean::Crate) -> plugins::PluginResult {
|
|
||||||
struct PrivacyCollapser {
|
|
||||||
stack: ~[clean::Visibility]
|
|
||||||
}
|
|
||||||
impl fold::DocFolder for PrivacyCollapser {
|
|
||||||
fn fold_item(&mut self, mut i: Item) -> Option<Item> {
|
|
||||||
if i.visibility.is_some() {
|
|
||||||
if i.visibility == Some(ast::inherited) {
|
|
||||||
i.visibility = Some(self.stack.last().clone());
|
|
||||||
} else {
|
|
||||||
self.stack.push(i.visibility.clone().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.fold_item_recur(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut privacy = PrivacyCollapser { stack: ~[] };
|
|
||||||
let crate = privacy.fold_crate(crate);
|
|
||||||
(crate, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn collapse_docs(crate: clean::Crate) -> plugins::PluginResult {
|
pub fn collapse_docs(crate: clean::Crate) -> plugins::PluginResult {
|
||||||
struct Collapser;
|
struct Collapser;
|
||||||
impl fold::DocFolder for Collapser {
|
impl fold::DocFolder for Collapser {
|
||||||
|
|
|
@ -45,6 +45,24 @@ pub mod visit_ast;
|
||||||
|
|
||||||
pub static SCHEMA_VERSION: &'static str = "0.8.0";
|
pub static SCHEMA_VERSION: &'static str = "0.8.0";
|
||||||
|
|
||||||
|
type Pass = (&'static str, // name
|
||||||
|
extern fn(clean::Crate) -> plugins::PluginResult, // fn
|
||||||
|
&'static str); // description
|
||||||
|
|
||||||
|
static PASSES: &'static [Pass] = &[
|
||||||
|
("strip-hidden", passes::strip_hidden,
|
||||||
|
"strips all doc(hidden) items from the output"),
|
||||||
|
("unindent-comments", passes::unindent_comments,
|
||||||
|
"removes excess indentation on comments in order for markdown to like it"),
|
||||||
|
("collapse-docs", passes::collapse_docs,
|
||||||
|
"concatenates all document attributes into one document attribute"),
|
||||||
|
];
|
||||||
|
|
||||||
|
static DEFAULT_PASSES: &'static [&'static str] = &[
|
||||||
|
"unindent-comments",
|
||||||
|
"collapse-docs",
|
||||||
|
];
|
||||||
|
|
||||||
local_data_key!(pub ctxtkey: @core::DocContext)
|
local_data_key!(pub ctxtkey: @core::DocContext)
|
||||||
|
|
||||||
enum OutputFormat {
|
enum OutputFormat {
|
||||||
|
@ -61,7 +79,8 @@ pub fn opts() -> ~[groups::OptGroup] {
|
||||||
optmulti("L", "library-path", "directory to add to crate search path",
|
optmulti("L", "library-path", "directory to add to crate search path",
|
||||||
"DIR"),
|
"DIR"),
|
||||||
optmulti("", "plugin-path", "directory to load plugins from", "DIR"),
|
optmulti("", "plugin-path", "directory to load plugins from", "DIR"),
|
||||||
optmulti("", "passes", "space separated list of passes to also run",
|
optmulti("", "passes", "space separated list of passes to also run, a \
|
||||||
|
value of `list` will print available passes",
|
||||||
"PASSES"),
|
"PASSES"),
|
||||||
optmulti("", "plugins", "space separated list of plugins to also load",
|
optmulti("", "plugins", "space separated list of plugins to also load",
|
||||||
"PLUGINS"),
|
"PLUGINS"),
|
||||||
|
@ -86,6 +105,22 @@ pub fn main_args(args: &[~str]) -> int {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut default_passes = !matches.opt_present("nodefaults");
|
||||||
|
let mut passes = matches.opt_strs("passes");
|
||||||
|
let mut plugins = matches.opt_strs("plugins");
|
||||||
|
|
||||||
|
if passes == ~[~"list"] {
|
||||||
|
println("Available passes for running rustdoc:");
|
||||||
|
for &(name, _, description) in PASSES.iter() {
|
||||||
|
println!("{:>20s} - {}", name, description);
|
||||||
|
}
|
||||||
|
println("\nDefault passes for rustdoc:");
|
||||||
|
for &name in DEFAULT_PASSES.iter() {
|
||||||
|
println!("{:>20s}", name);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let (format, cratefile) = match matches.free.clone() {
|
let (format, cratefile) = match matches.free.clone() {
|
||||||
[~"json", crate] => (JSON, crate),
|
[~"json", crate] => (JSON, crate),
|
||||||
[~"html", crate] => (HTML, crate),
|
[~"html", crate] => (HTML, crate),
|
||||||
|
@ -118,9 +153,6 @@ pub fn main_args(args: &[~str]) -> int {
|
||||||
|
|
||||||
// Process all of the crate attributes, extracting plugin metadata along
|
// Process all of the crate attributes, extracting plugin metadata along
|
||||||
// with the passes which we are supposed to run.
|
// with the passes which we are supposed to run.
|
||||||
let mut default_passes = !matches.opt_present("nodefaults");
|
|
||||||
let mut passes = matches.opt_strs("passes");
|
|
||||||
let mut plugins = matches.opt_strs("plugins");
|
|
||||||
match crate.module.get_ref().doc_list() {
|
match crate.module.get_ref().doc_list() {
|
||||||
Some(nested) => {
|
Some(nested) => {
|
||||||
for inner in nested.iter() {
|
for inner in nested.iter() {
|
||||||
|
@ -145,19 +177,20 @@ pub fn main_args(args: &[~str]) -> int {
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
if default_passes {
|
if default_passes {
|
||||||
passes.unshift(~"collapse-docs");
|
for name in DEFAULT_PASSES.rev_iter() {
|
||||||
passes.unshift(~"unindent-comments");
|
passes.unshift(name.to_owned());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load all plugins/passes into a PluginManager
|
// Load all plugins/passes into a PluginManager
|
||||||
let mut pm = plugins::PluginManager::new(Path("/tmp/rustdoc_ng/plugins"));
|
let mut pm = plugins::PluginManager::new(Path("/tmp/rustdoc_ng/plugins"));
|
||||||
for pass in passes.iter() {
|
for pass in passes.iter() {
|
||||||
let plugin = match pass.as_slice() {
|
let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) {
|
||||||
"strip-hidden" => passes::strip_hidden,
|
Some(i) => PASSES[i].n1(),
|
||||||
"unindent-comments" => passes::unindent_comments,
|
None => {
|
||||||
"collapse-docs" => passes::collapse_docs,
|
error2!("unknown pass {}, skipping", *pass);
|
||||||
"collapse-privacy" => passes::collapse_privacy,
|
loop
|
||||||
s => { error!("unknown pass %s, skipping", s); loop },
|
},
|
||||||
};
|
};
|
||||||
pm.add_plugin(plugin);
|
pm.add_plugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue