From 5fea49e639fd0d157c68ea478219436da749b489 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 24 Feb 2023 17:11:35 -0800 Subject: [PATCH] Pass the 'Save' format trigger when formatting on save In an earlier refactor, I accidentally caused the 'Manual' trigger to *always* be passed. Co-authored-by: Mikayla Maki --- crates/editor/src/editor.rs | 7 +++---- crates/editor/src/editor_tests.rs | 8 ++++++-- crates/editor/src/items.rs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4de91fbaf8..2cc26c26ed 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5459,21 +5459,20 @@ impl Editor { None => return None, }; - Some(self.perform_format(project, cx)) + Some(self.perform_format(project, FormatTrigger::Manual, cx)) } fn perform_format( &mut self, project: ModelHandle, + trigger: FormatTrigger, cx: &mut ViewContext<'_, Self>, ) -> Task> { let buffer = self.buffer().clone(); let buffers = buffer.read(cx).all_buffers(); let mut timeout = cx.background().timer(FORMAT_TIMEOUT).fuse(); - let format = project.update(cx, |project, cx| { - project.format(buffers, true, FormatTrigger::Manual, cx) - }); + let format = project.update(cx, |project, cx| project.format(buffers, true, trigger, cx)); cx.spawn(|_, mut cx| async move { let transaction = futures::select_biased! { diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 94699a8d5a..b0ce4a68b9 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -4193,7 +4193,9 @@ async fn test_document_format_manual_trigger(cx: &mut gpui::TestAppContext) { let (_, editor) = cx.add_window(|cx| build_editor(buffer, cx)); editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx)); - let format = editor.update(cx, |editor, cx| editor.perform_format(project.clone(), cx)); + let format = editor.update(cx, |editor, cx| { + editor.perform_format(project.clone(), FormatTrigger::Manual, cx) + }); fake_server .handle_request::(move |params, _| async move { assert_eq!( @@ -4225,7 +4227,9 @@ async fn test_document_format_manual_trigger(cx: &mut gpui::TestAppContext) { futures::future::pending::<()>().await; unreachable!() }); - let format = editor.update(cx, |editor, cx| editor.perform_format(project, cx)); + let format = editor.update(cx, |editor, cx| { + editor.perform_format(project, FormatTrigger::Manual, cx) + }); cx.foreground().advance_clock(super::FORMAT_TIMEOUT); cx.foreground().start_waiting(); format.await.unwrap(); diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 47963597f6..b0b368acd6 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -14,7 +14,7 @@ use language::{ proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, OffsetRangeExt, Point, SelectionGoal, }; -use project::{Item as _, Project, ProjectPath}; +use project::{FormatTrigger, Item as _, Project, ProjectPath}; use rpc::proto::{self, update_view}; use settings::Settings; use smallvec::SmallVec; @@ -608,7 +608,7 @@ impl Item for Editor { cx: &mut ViewContext, ) -> Task> { self.report_event("save editor", cx); - let format = self.perform_format(project.clone(), cx); + let format = self.perform_format(project.clone(), FormatTrigger::Save, cx); let buffers = self.buffer().clone().read(cx).all_buffers(); cx.as_mut().spawn(|mut cx| async move { format.await?;