on master help sign in
Editor::flush_writes returns an error
e645804Skyler Hawthorne
helix-term/src/application.rs+4−1
@@ -977,7 +977,10 @@ impl Application {
977 errs.push(err);
977 errs.push(err);
978 };
978 };
979
979
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+ }
981
984
982 if self.editor.close_language_servers(None).await.is_err() {
985 if self.editor.close_language_servers(None).await.is_err() {
983 log::error!("Timed out waiting for language servers to shutdown");
986 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) ->
75}
75}
76
76
77fn buffer_close_by_ids_impl(
77fn buffer_close_by_ids_impl(
78− editor: &mut Editor,
78+ cx: &mut compositor::Context,
79 doc_ids: &[DocumentId],
79 doc_ids: &[DocumentId],
80 force: bool,
80 force: bool,
81) -> anyhow::Result<()> {
81) -> anyhow::Result<()> {
82− // TODO: deduplicate with ctx.block_try_flush_writes
82+ cx.block_try_flush_writes()?;
83− tokio::task::block_in_place(|| helix_lsp::block_on(editor.flush_writes()));
84
83
85 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
84 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
86 .iter()
85 .iter()
87 .filter_map(|&doc_id| {
86 .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) {
89 Some((doc_id, name))
88 Some((doc_id, name))
90 } else {
89 } else {
91 None
90 None
@@ -94,11 +93,11 @@ fn buffer_close_by_ids_impl(
94 .unzip();
93 .unzip();
95
94
96 if let Some(first) = modified_ids.first() {
95 if let Some(first) = modified_ids.first() {
97− let current = doc!(editor);
96+ let current = doc!(cx.editor);
98 // If the current document is unmodified, and there are modified
97 // If the current document is unmodified, and there are modified
99 // documents, switch focus to the first modified doc.
98 // documents, switch focus to the first modified doc.
100 if !modified_ids.contains(&current.id()) {
99 if !modified_ids.contains(&current.id()) {
101− editor.switch(*first, Action::Replace);
100+ cx.editor.switch(*first, Action::Replace);
102 }
101 }
103 bail!(
102 bail!(
104 "{} unsaved buffer(s) remaining: {:?}",
103 "{} unsaved buffer(s) remaining: {:?}",
@@ -157,7 +156,7 @@ fn buffer_close(
157 }
156 }
158
157
159 let document_ids = buffer_gather_paths_impl(cx.editor, args);
158 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)
161}
160}
162
161
163fn force_buffer_close(
162fn force_buffer_close(
@@ -170,7 +169,7 @@ fn force_buffer_close(
170 }
169 }
171
170
172 let document_ids = buffer_gather_paths_impl(cx.editor, args);
171 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)
174}
173}
175
174
176fn buffer_gather_others_impl(editor: &mut Editor) -> Vec<DocumentId> {
175fn buffer_gather_others_impl(editor: &mut Editor) -> Vec<DocumentId> {
@@ -192,7 +191,7 @@ fn buffer_close_others(
192 }
191 }
193
192
194 let document_ids = buffer_gather_others_impl(cx.editor);
193 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)
196}
195}
197
196
198fn force_buffer_close_others(
197fn force_buffer_close_others(
@@ -205,7 +204,7 @@ fn force_buffer_close_others(
205 }
204 }
206
205
207 let document_ids = buffer_gather_others_impl(cx.editor);
206 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)
209}
208}
210
209
211fn buffer_gather_all_impl(editor: &mut Editor) -> Vec<DocumentId> {
210fn buffer_gather_all_impl(editor: &mut Editor) -> Vec<DocumentId> {
@@ -222,7 +221,7 @@ fn buffer_close_all(
222 }
221 }
223
222
224 let document_ids = buffer_gather_all_impl(cx.editor);
223 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)
226}
225}
227
226
228fn force_buffer_close_all(
227fn force_buffer_close_all(
@@ -235,7 +234,7 @@ fn force_buffer_close_all(
235 }
234 }
236
235
237 let document_ids = buffer_gather_all_impl(cx.editor);
236 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)
239}
238}
240
239
241fn buffer_next(
240fn buffer_next(
helix-term/src/compositor.rs+1−3
@@ -32,9 +32,7 @@ impl<'a> Context<'a> {
32 /// operations for all documents.
32 /// operations for all documents.
33 pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
33 pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
34 tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?;
34 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()));
35+ tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()))?;
37−
38 Ok(())
36 Ok(())
39 }
37 }
40}
38}
helix-view/src/editor.rs+12−10
@@ -29,7 +29,7 @@ use tokio::{
29 time::{sleep, Duration, Instant, Sleep},
29 time::{sleep, Duration, Instant, Sleep},
30};
30};
31
31
32−use anyhow::{anyhow, Error};
32+use anyhow::{anyhow, bail, Error};
33
33
34pub use helix_core::diagnostic::Severity;
34pub use helix_core::diagnostic::Severity;
35pub use helix_core::register::Registers;
35pub use helix_core::register::Registers;
@@ -1355,22 +1355,24 @@ impl Editor {
1355 }
1355 }
1356 }
1356 }
1357
1357
1358− pub async fn flush_writes(&mut self) {
1358+ pub async fn flush_writes(&mut self) -> anyhow::Result<()> {
1359 while self.write_count > 0 {
1359 while self.write_count > 0 {
1360 if let Some(save_event) = self.save_queue.next().await {
1360 if let Some(save_event) = self.save_queue.next().await {
1361+ self.write_count -= 1;
1362+
1361− match &save_event {
1363+ let save_event = match save_event {
1362− Ok(event) => {
1364+ Ok(event) => event,
1363− let doc = doc_mut!(self, &event.doc_id);
1364− doc.set_last_saved_revision(event.revision);
1365− }
1366 Err(err) => {
1365 Err(err) => {
1367− log::error!("error saving document: {}", err);
1366+ self.set_error(err.to_string());
1367+ bail!(err);
1368 }
1368 }
1369 };
1369 };
1370− // TODO: if is_err: break?
1371
1370
1372− self.write_count -= 1;
1371+ let doc = doc_mut!(self, &save_event.doc_id);
1372+ doc.set_last_saved_revision(save_event.revision);
1373 }
1373 }
1374 }
1374 }
1375+
1376+ Ok(())
1375 }
1377 }
1376}
1378}