@@ -890,12 +890,12 @@ mod cmd {
892 fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
892 fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
893− let id = editor.view().doc;
893+ let (view, doc) = editor.current();
894− let doc = &mut editor.documents[id];
895 if doc.path().is_none() {
894 if doc.path().is_none() {
896 editor.set_error("cannot write a buffer without a filename".to_string());
895 editor.set_error("cannot write a buffer without a filename".to_string());
898+ doc.format(view.id); // TODO: merge into save
899 tokio::spawn(doc.save());
899 tokio::spawn(doc.save());
@@ -906,25 +906,7 @@ mod cmd {
906 fn format(editor: &mut Editor, args: &[&str], event: PromptEvent) {
906 fn format(editor: &mut Editor, args: &[&str], event: PromptEvent) {
907 let (view, doc) = editor.current();
907 let (view, doc) = editor.current();
909− if let Some(language_server) = doc.language_server() {
909+ doc.format(view.id)
910− // TODO: await, no blocking
911− let transaction = helix_lsp::block_on(
913− .text_document_formatting(doc.identifier(), lsp::FormattingOptions::default()),
916− helix_lsp::util::generate_transaction_from_edits(
919− language_server.offset_encoding(),
923− if let Ok(transaction) = transaction {
924− doc.apply(&transaction, view.id);
925− doc.append_changes_to_history(view.id);
930 pub const COMMAND_LIST: &[Command] = &[
912 pub const COMMAND_LIST: &[Command] = &[
@@ -2277,7 +2259,8 @@ pub fn space_mode(cx: &mut Context) {
2277 'v' => vsplit(cx),
2259 'v' => vsplit(cx),
2278 'w' => {
2260 'w' => {
2279 // save current buffer
2261 // save current buffer
2280− let doc = cx.doc();
2262+ let (view, doc) = cx.current();
2263+ doc.format(view.id); // TODO: merge into save
2281 tokio::spawn(doc.save());
2264 tokio::spawn(doc.save());
2283 'c' => {
2266 'c' => {