Skip to content

Commit 9e26fea

Browse files
committed
Remove Session
1 parent 41e0a42 commit 9e26fea

File tree

6 files changed

+207
-251
lines changed

6 files changed

+207
-251
lines changed

rustfmt-core/rustfmt-bin/src/bin/main.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use thiserror::Error;
1616
use rustfmt_lib::{
1717
emitter::{emit_format_report, EmitMode, EmitterConfig, Verbosity},
1818
load_config, CliOptions, Config, Edition, FileLines, FileName, FormatReport,
19-
FormatReportFormatterBuilder, Input, RustFormatterBuilder, Session,
19+
FormatReportFormatterBuilder, Input, OperationSetting,
2020
};
2121

2222
fn main() {
@@ -414,18 +414,13 @@ fn format_string(input: String, opt: Opt) -> Result<i32> {
414414
}
415415

416416
let out = &mut stdout();
417-
let mut session = RustFormatterBuilder::default()
418-
.recursive(opt.recursive)
419-
.verbosity(Verbosity::Quiet)
420-
.build();
417+
let setting = OperationSetting {
418+
recursive: opt.recursive,
419+
verbosity: Verbosity::Quiet,
420+
};
421421
let mut format_report = FormatReport::new();
422422
// FIXME: Add error handling.
423-
format_and_emit_report(
424-
&mut session,
425-
Input::Text(input),
426-
&config,
427-
&mut format_report,
428-
);
423+
format_and_emit_report(Input::Text(input), &config, setting, &mut format_report);
429424
let has_diff = emit_format_report(format_report, out, opt.emitter_config(EmitMode::Stdout))?;
430425
Ok(if opt.check && has_diff { 1 } else { 0 })
431426
}
@@ -498,10 +493,10 @@ fn format(opt: Opt) -> Result<i32> {
498493
}
499494
}
500495

501-
let mut session = RustFormatterBuilder::default()
502-
.recursive(opt.recursive)
503-
.verbosity(opt.verbosity())
504-
.build();
496+
let setting = OperationSetting {
497+
recursive: opt.recursive,
498+
verbosity: opt.verbosity(),
499+
};
505500
let mut format_report = FormatReport::new();
506501

507502
for pair in FileConfigPairIter::new(&opt, config_path.is_some()) {
@@ -519,16 +514,16 @@ fn format(opt: Opt) -> Result<i32> {
519514
}
520515

521516
format_and_emit_report(
522-
&mut session,
523517
Input::File(file.to_path_buf()),
524518
&local_config,
519+
setting,
525520
&mut format_report,
526521
);
527522
} else {
528523
format_and_emit_report(
529-
&mut session,
530524
Input::File(file.to_path_buf()),
531525
&config,
526+
setting,
532527
&mut format_report,
533528
);
534529
}
@@ -550,12 +545,12 @@ fn format(opt: Opt) -> Result<i32> {
550545
}
551546

552547
fn format_and_emit_report(
553-
session: &mut Session,
554548
input: Input,
555549
config: &Config,
550+
operation_setting: OperationSetting,
556551
format_report: &mut FormatReport,
557552
) {
558-
match session.format(input, config) {
553+
match rustfmt_lib::format(input, config, operation_setting) {
559554
Ok(report) => {
560555
format_report.merge(report);
561556
}

rustfmt-core/rustfmt-bin/src/git-rustfmt/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use structopt::StructOpt;
99

1010
use rustfmt_lib::{
1111
emitter::{emit_format_report, EmitterConfig},
12-
load_config, CliOptions, FormatReportFormatterBuilder, Input, Session,
12+
format, load_config, CliOptions, FormatReportFormatterBuilder, Input, OperationSetting,
1313
};
1414

1515
fn prune_files(files: Vec<&str>) -> Vec<&str> {
@@ -59,13 +59,11 @@ fn get_files(input: &str) -> Vec<&str> {
5959
fn fmt_files(files: &[&str]) -> i32 {
6060
let (config, _) =
6161
load_config::<NullOptions>(Some(Path::new(".")), None).expect("couldn't load config");
62+
let setting = OperationSetting::default();
6263

6364
let mut out = stdout();
64-
let mut session = Session::default();
6565
for file in files {
66-
let report = session
67-
.format(Input::File(PathBuf::from(file)), &config)
68-
.unwrap();
66+
let report = format(Input::File(PathBuf::from(file)), &config, setting).unwrap();
6967
if report.has_warnings() {
7068
eprintln!("{}", FormatReportFormatterBuilder::new(&report).build());
7169
}

0 commit comments

Comments
 (0)