From b3fc31a211293f48696d26855781577d1859c2c6 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Fri, 2 Sep 2022 09:20:28 -0400 Subject: move language server refresh to document saved event handler --- helix-term/src/application.rs | 42 +++++++++++++++++++++++++++--------------- helix-term/src/commands.rs | 9 +-------- 2 files changed, 28 insertions(+), 23 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 793993ee..60610c1d 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -462,22 +462,34 @@ impl Application { let lines = doc_save_event.text.len_lines(); let bytes = doc_save_event.text.len_bytes(); - if let Err(err) = doc.set_path(Some(&doc_save_event.path)) { - log::error!( - "error setting path for doc '{:?}': {}", - doc.path(), - err.to_string(), - ); - self.editor.set_error(err.to_string()); - } else { - // TODO: fix being overwritten by lsp - self.editor.set_status(format!( - "'{}' written, {}L {}B", - get_relative_path(&doc_save_event.path).to_string_lossy(), - lines, - bytes - )); + if doc.path() != Some(&doc_save_event.path) { + if let Err(err) = doc.set_path(Some(&doc_save_event.path)) { + log::error!( + "error setting path for doc '{:?}': {}", + doc.path(), + err.to_string(), + ); + + self.editor.set_error(err.to_string()); + return; + } + + let loader = self.editor.syn_loader.clone(); + + // borrowing the same doc again to get around the borrow checker + let doc = self.editor.document_mut(doc_save_event.doc_id).unwrap(); + let id = doc.id(); + doc.detect_language(loader); + let _ = self.editor.refresh_language_server(id); } + + // TODO: fix being overwritten by lsp + self.editor.set_status(format!( + "'{}' written, {}L {}B", + get_relative_path(&doc_save_event.path).to_string_lossy(), + lines, + bytes + )); } #[inline(always)] diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index afd94564..6deecbe2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2519,7 +2519,7 @@ async fn make_format_callback( write: Option<(Option, bool)>, ) -> anyhow::Result { let format = format.await?; - let call: job::Callback = Callback::EditorCompositor(Box::new(move |editor, _compositor| { + let call: job::Callback = Callback::Editor(Box::new(move |editor| { if !editor.documents.contains_key(&doc_id) { return; } @@ -2527,7 +2527,6 @@ async fn make_format_callback( let scrolloff = editor.config().scrolloff; let doc = doc_mut!(editor, &doc_id); let view = view_mut!(editor); - let loader = editor.syn_loader.clone(); if doc.version() == doc_version { apply_transaction(&format, doc, view); @@ -2536,14 +2535,8 @@ async fn make_format_callback( view.ensure_cursor_in_view(doc, scrolloff); if let Some((path, force)) = write { - let refresh_lang = path.is_some(); - if let Err(err) = doc.save(path, force) { editor.set_error(format!("Error saving: {}", err)); - } else if refresh_lang { - let id = doc.id(); - doc.detect_language(loader); - let _ = editor.refresh_language_server(id); } } } else { -- cgit v1.2.3-70-g09d2