on master help sign in
fix(commands): run fmt for all documents being closed (#1444)
38ca8daMatouš Dzivjak
helix-term/src/commands.rs+18−4
@@ -2279,7 +2279,7 @@ pub mod cmd {
2279 force: bool,
2279 force: bool,
2280 ) -> anyhow::Result<()> {
2280 ) -> anyhow::Result<()> {
2281 let mut errors = String::new();
2281 let mut errors = String::new();
2282−
2282+ let jobs = &mut cx.jobs;
2283 // save all documents
2283 // save all documents
2284 for doc in &mut cx.editor.documents.values_mut() {
2284 for doc in &mut cx.editor.documents.values_mut() {
2285 if doc.path().is_none() {
2285 if doc.path().is_none() {
@@ -2287,9 +2287,23 @@ pub mod cmd {
2287 continue;
2287 continue;
2288 }
2288 }
2289
2289
2290− // TODO: handle error.
2290+ if !doc.is_modified() {
2291− let handle = doc.save();
2291+ continue;
2292+ }
2293+
2294+ let fmt = doc.auto_format().map(|fmt| {
2295+ let shared = fmt.shared();
2296+ let callback = make_format_callback(
2297+ doc.id(),
2298+ doc.version(),
2299+ Modified::SetUnmodified,
2300+ shared.clone(),
2301+ );
2302+ jobs.callback(callback);
2303+ shared
2304+ });
2305+ let future = doc.format_and_save(fmt);
2292− cx.jobs.add(Job::new(handle).wait_before_exiting());
2306+ jobs.add(Job::new(future).wait_before_exiting());
2293 }
2307 }
2294
2308
2295 if quit {
2309 if quit {