on master help sign in
Editor::flush_writes returns an error
commite645804b0a8e42c9fb9ef8259a9b2ad47a57a6e6 authorSkyler Hawthorne <skyler@dead10ck.com> dateSun 16 Oct 2022, 21:40 (4 years ago) parent52ba550
4 files changed+28−26
helix-term/src/application.rs+4−1 helix-term/src/commands/typed.rs+11−12 helix-term/src/compositor.rs+1−3 helix-view/src/editor.rs+12−10
helix-term/src/application.rs+4−1
@@ -977,7 +977,10 @@ impl Application {
977977 errs.push(err);
978978 };
979979
980− self.editor.flush_writes().await;
980+ if let Err(err) = self.editor.flush_writes().await {
981+ log::error!("Error writing: {}", err);
982+ errs.push(err);
983+ }
981984
982985 if self.editor.close_language_servers(None).await.is_err() {
983986 log::error!("Timed out waiting for language servers to shutdown");
helix-term/src/commands/typed.rs+11−12
@@ -75,17 +75,16 @@ fn open(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
7575}
7676
7777fn buffer_close_by_ids_impl(
78− editor: &mut Editor,
78+ cx: &mut compositor::Context,
7979 doc_ids: &[DocumentId],
8080 force: bool,
8181) -> anyhow::Result<()> {
82− // TODO: deduplicate with ctx.block_try_flush_writes
83− tokio::task::block_in_place(|| helix_lsp::block_on(editor.flush_writes()));
82+ cx.block_try_flush_writes()?;
8483
8584 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
8685 .iter()
8786 .filter_map(|&doc_id| {
88− if let Err(CloseError::BufferModified(name)) = editor.close_document(doc_id, force) {
87+ if let Err(CloseError::BufferModified(name)) = cx.editor.close_document(doc_id, force) {
8988 Some((doc_id, name))
9089 } else {
9190 None
@@ -94,11 +93,11 @@ fn buffer_close_by_ids_impl(
9493 .unzip();
9594
9695 if let Some(first) = modified_ids.first() {
97− let current = doc!(editor);
96+ let current = doc!(cx.editor);
9897 // If the current document is unmodified, and there are modified
9998 // documents, switch focus to the first modified doc.
10099 if !modified_ids.contains(&current.id()) {
101− editor.switch(*first, Action::Replace);
100+ cx.editor.switch(*first, Action::Replace);
102101 }
103102 bail!(
104103 "{} unsaved buffer(s) remaining: {:?}",
@@ -157,7 +156,7 @@ fn buffer_close(
157156 }
158157
159158 let document_ids = buffer_gather_paths_impl(cx.editor, args);
160− buffer_close_by_ids_impl(cx.editor, &document_ids, false)
159+ buffer_close_by_ids_impl(cx, &document_ids, false)
161160}
162161
163162fn force_buffer_close(
@@ -170,7 +169,7 @@ fn force_buffer_close(
170169 }
171170
172171 let document_ids = buffer_gather_paths_impl(cx.editor, args);
173− buffer_close_by_ids_impl(cx.editor, &document_ids, true)
172+ buffer_close_by_ids_impl(cx, &document_ids, true)
174173}
175174
176175fn buffer_gather_others_impl(editor: &mut Editor) -> Vec<DocumentId> {
@@ -192,7 +191,7 @@ fn buffer_close_others(
192191 }
193192
194193 let document_ids = buffer_gather_others_impl(cx.editor);
195− buffer_close_by_ids_impl(cx.editor, &document_ids, false)
194+ buffer_close_by_ids_impl(cx, &document_ids, false)
196195}
197196
198197fn force_buffer_close_others(
@@ -205,7 +204,7 @@ fn force_buffer_close_others(
205204 }
206205
207206 let document_ids = buffer_gather_others_impl(cx.editor);
208− buffer_close_by_ids_impl(cx.editor, &document_ids, true)
207+ buffer_close_by_ids_impl(cx, &document_ids, true)
209208}
210209
211210fn buffer_gather_all_impl(editor: &mut Editor) -> Vec<DocumentId> {
@@ -222,7 +221,7 @@ fn buffer_close_all(
222221 }
223222
224223 let document_ids = buffer_gather_all_impl(cx.editor);
225− buffer_close_by_ids_impl(cx.editor, &document_ids, false)
224+ buffer_close_by_ids_impl(cx, &document_ids, false)
226225}
227226
228227fn force_buffer_close_all(
@@ -235,7 +234,7 @@ fn force_buffer_close_all(
235234 }
236235
237236 let document_ids = buffer_gather_all_impl(cx.editor);
238− buffer_close_by_ids_impl(cx.editor, &document_ids, true)
237+ buffer_close_by_ids_impl(cx, &document_ids, true)
239238}
240239
241240fn buffer_next(
helix-term/src/compositor.rs+1−3
@@ -32,9 +32,7 @@ impl<'a> Context<'a> {
3232 /// operations for all documents.
3333 pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
3434 tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?;
35−
36− tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()));
37−
35+ tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()))?;
3836 Ok(())
3937 }
4038}
helix-view/src/editor.rs+12−10
@@ -29,7 +29,7 @@ use tokio::{
2929 time::{sleep, Duration, Instant, Sleep},
3030};
3131
32−use anyhow::{anyhow, Error};
32+use anyhow::{anyhow, bail, Error};
3333
3434pub use helix_core::diagnostic::Severity;
3535pub use helix_core::register::Registers;
@@ -1355,22 +1355,24 @@ impl Editor {
13551355 }
13561356 }
13571357
1358− pub async fn flush_writes(&mut self) {
1358+ pub async fn flush_writes(&mut self) -> anyhow::Result<()> {
13591359 while self.write_count > 0 {
13601360 if let Some(save_event) = self.save_queue.next().await {
1361− match &save_event {
1362− Ok(event) => {
1363− let doc = doc_mut!(self, &event.doc_id);
1364− doc.set_last_saved_revision(event.revision);
1365− }
1361+ self.write_count -= 1;
1362+
1363+ let save_event = match save_event {
1364+ Ok(event) => event,
13661365 Err(err) => {
1367− log::error!("error saving document: {}", err);
1366+ self.set_error(err.to_string());
1367+ bail!(err);
13681368 }
13691369 };
1370− // TODO: if is_err: break?
13711370
1372− self.write_count -= 1;
1371+ let doc = doc_mut!(self, &save_event.doc_id);
1372+ doc.set_last_saved_revision(save_event.revision);
13731373 }
13741374 }
1375+
1376+ Ok(())
13751377 }
13761378}