@@ -890,12 +890,12 @@ mod cmd {
890890 }
891891
892892 fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
893− let id = editor.view().doc;
894− let doc = &mut editor.documents[id];
893+ let (view, doc) = editor.current();
895894 if doc.path().is_none() {
896895 editor.set_error("cannot write a buffer without a filename".to_string());
897896 return;
898897 }
898+ doc.format(view.id); // TODO: merge into save
899899 tokio::spawn(doc.save());
900900 }
901901
@@ -906,25 +906,7 @@ mod cmd {
906906 fn format(editor: &mut Editor, args: &[&str], event: PromptEvent) {
907907 let (view, doc) = editor.current();
908908
909− if let Some(language_server) = doc.language_server() {
910− // TODO: await, no blocking
911− let transaction = helix_lsp::block_on(
912− language_server
913− .text_document_formatting(doc.identifier(), lsp::FormattingOptions::default()),
914− )
915− .map(|edits| {
916− helix_lsp::util::generate_transaction_from_edits(
917− doc.text(),
918− edits,
919− language_server.offset_encoding(),
920− )
921− });
922−
923− if let Ok(transaction) = transaction {
924− doc.apply(&transaction, view.id);
925− doc.append_changes_to_history(view.id);
926− }
927− }
909+ doc.format(view.id)
928910 }
929911
930912 pub const COMMAND_LIST: &[Command] = &[
@@ -2277,7 +2259,8 @@ pub fn space_mode(cx: &mut Context) {
22772259 'v' => vsplit(cx),
22782260 'w' => {
22792261 // save current buffer
2280− let doc = cx.doc();
2262+ let (view, doc) = cx.current();
2263+ doc.format(view.id); // TODO: merge into save
22812264 tokio::spawn(doc.save());
22822265 }
22832266 'c' => {