add option to ignore out of line modules

This commit is contained in:
Aleksey Kladov 2015-12-23 17:25:49 +03:00
parent 47f473dbd9
commit a70b621607
3 changed files with 8 additions and 1 deletions

View File

@ -79,6 +79,7 @@ fn lookup_and_read_project_file(input_file: &Path) -> io::Result<(PathBuf, Strin
fn update_config(config: &mut Config, matches: &Matches) { fn update_config(config: &mut Config, matches: &Matches) {
config.verbose = matches.opt_present("verbose"); config.verbose = matches.opt_present("verbose");
config.skip_children = matches.opt_present("skip-children");
} }
fn execute() -> i32 { fn execute() -> i32 {
@ -90,6 +91,7 @@ fn execute() -> i32 {
"write-mode", "write-mode",
"mode to write in (not usable when piping from stdin)", "mode to write in (not usable when piping from stdin)",
"[replace|overwrite|display|diff|coverage]"); "[replace|overwrite|display|diff|coverage]");
opts.optflag("", "skip-children", "don't reformat child modules");
opts.optflag("", opts.optflag("",
"config-help", "config-help",

View File

@ -259,6 +259,7 @@ macro_rules! create_config {
create_config! { create_config! {
verbose: bool, false, "Use verbose output"; verbose: bool, false, "Use verbose output";
skip_children: bool, false, "Don't reformat out of line modules";
max_width: usize, 100, "Maximum width of each line"; max_width: usize, 100, "Maximum width of each line";
ideal_width: usize, 80, "Ideal width of each line"; ideal_width: usize, 80, "Ideal width of each line";
tab_spaces: usize, 4, "Number of spaces per tab"; tab_spaces: usize, 4, "Number of spaces per tab";

View File

@ -298,11 +298,15 @@ impl fmt::Display for FormatReport {
// Formatting which depends on the AST. // Formatting which depends on the AST.
fn fmt_ast(krate: &ast::Crate, fn fmt_ast(krate: &ast::Crate,
parse_session: &ParseSess, parse_session: &ParseSess,
main_file: &Path,
config: &Config, config: &Config,
mode: WriteMode) mode: WriteMode)
-> FileMap { -> FileMap {
let mut file_map = FileMap::new(); let mut file_map = FileMap::new();
for (path, module) in modules::list_files(krate, parse_session.codemap()) { for (path, module) in modules::list_files(krate, parse_session.codemap()) {
if config.skip_children && path.as_path() != main_file {
continue;
}
let path = path.to_str().unwrap(); let path = path.to_str().unwrap();
if config.verbose { if config.verbose {
println!("Formatting {}", path); println!("Formatting {}", path);
@ -431,7 +435,7 @@ pub fn format(file: &Path, config: &Config, mode: WriteMode) -> FileMap {
let emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None)); let emitter = Box::new(EmitterWriter::new(Box::new(Vec::new()), None));
parse_session.span_diagnostic.handler = Handler::with_emitter(false, emitter); parse_session.span_diagnostic.handler = Handler::with_emitter(false, emitter);
let mut file_map = fmt_ast(&krate, &parse_session, config, mode); let mut file_map = fmt_ast(&krate, &parse_session, file, config, mode);
// For some reason, the codemap does not include terminating // For some reason, the codemap does not include terminating
// newlines so we must add one on for each file. This is sad. // newlines so we must add one on for each file. This is sad.