mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 12:13:43 +00:00
add option to ignore out of line modules
This commit is contained in:
parent
47f473dbd9
commit
a70b621607
@ -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) {
|
||||
config.verbose = matches.opt_present("verbose");
|
||||
config.skip_children = matches.opt_present("skip-children");
|
||||
}
|
||||
|
||||
fn execute() -> i32 {
|
||||
@ -90,6 +91,7 @@ fn execute() -> i32 {
|
||||
"write-mode",
|
||||
"mode to write in (not usable when piping from stdin)",
|
||||
"[replace|overwrite|display|diff|coverage]");
|
||||
opts.optflag("", "skip-children", "don't reformat child modules");
|
||||
|
||||
opts.optflag("",
|
||||
"config-help",
|
||||
|
@ -259,6 +259,7 @@ macro_rules! create_config {
|
||||
|
||||
create_config! {
|
||||
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";
|
||||
ideal_width: usize, 80, "Ideal width of each line";
|
||||
tab_spaces: usize, 4, "Number of spaces per tab";
|
||||
|
@ -298,11 +298,15 @@ impl fmt::Display for FormatReport {
|
||||
// Formatting which depends on the AST.
|
||||
fn fmt_ast(krate: &ast::Crate,
|
||||
parse_session: &ParseSess,
|
||||
main_file: &Path,
|
||||
config: &Config,
|
||||
mode: WriteMode)
|
||||
-> FileMap {
|
||||
let mut file_map = FileMap::new();
|
||||
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();
|
||||
if config.verbose {
|
||||
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));
|
||||
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
|
||||
// newlines so we must add one on for each file. This is sad.
|
||||
|
Loading…
Reference in New Issue
Block a user