Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Pass the 'Save' format trigger when formatting on save
Max Brunsfeld5fea49e639fd
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 4de91fbaf8e..2cc26c26edc 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<Project>,+ trigger: FormatTrigger,cx: &mut ViewContext<'_, Self>,) -> Task<Result<()>> {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.rsindex 94699a8d5a3..b0ce4a68b90 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::<lsp::request::Formatting, _, _>(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.rsindex 47963597f6b..b0b368acd64 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<Self>,) -> Task<Result<()>> {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?;