aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-29 15:00:15 +0000
committerBlaž Hrastnik2021-05-29 15:00:15 +0000
commit2c48d65b1565cf68a3efb5c9e91e9011526f43e7 (patch)
tree25b8f9e9a84800ce6e16282e783172bc7238ef31 /helix-term/src
parentd5466eddf59a2a447e0f5067b325a55fa6ba2d90 (diff)
Format document on save
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs27
1 files changed, 5 insertions, 22 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 674f6d23..69e335dc 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -890,12 +890,12 @@ mod cmd {
}
fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
- let id = editor.view().doc;
- let doc = &mut editor.documents[id];
+ let (view, doc) = editor.current();
if doc.path().is_none() {
editor.set_error("cannot write a buffer without a filename".to_string());
return;
}
+ doc.format(view.id); // TODO: merge into save
tokio::spawn(doc.save());
}
@@ -906,25 +906,7 @@ mod cmd {
fn format(editor: &mut Editor, args: &[&str], event: PromptEvent) {
let (view, doc) = editor.current();
- if let Some(language_server) = doc.language_server() {
- // TODO: await, no blocking
- let transaction = helix_lsp::block_on(
- language_server
- .text_document_formatting(doc.identifier(), lsp::FormattingOptions::default()),
- )
- .map(|edits| {
- helix_lsp::util::generate_transaction_from_edits(
- doc.text(),
- edits,
- language_server.offset_encoding(),
- )
- });
-
- if let Ok(transaction) = transaction {
- doc.apply(&transaction, view.id);
- doc.append_changes_to_history(view.id);
- }
- }
+ doc.format(view.id)
}
pub const COMMAND_LIST: &[Command] = &[
@@ -2277,7 +2259,8 @@ pub fn space_mode(cx: &mut Context) {
'v' => vsplit(cx),
'w' => {
// save current buffer
- let doc = cx.doc();
+ let (view, doc) = cx.current();
+ doc.format(view.id); // TODO: merge into save
tokio::spawn(doc.save());
}
'c' => {