on master help sign in
Deduplicate flush_writes
commitb0212b36118f7a4d596510dabb0c011144c7af69 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 16 Oct 2022, 18:01 (4 years ago) parent30c9399
4 files changed+19−50
helix-term/src/application.rs+2−17 helix-term/src/commands/typed.rs+1−16 helix-term/src/compositor.rs+1−17 helix-view/src/editor.rs+15
helix-term/src/application.rs+2−17
@@ -1,5 +1,5 @@
11use arc_swap::{access::Map, ArcSwap};
2−use futures_util::{Stream, StreamExt};
2+use futures_util::Stream;
33use helix_core::{
44 diagnostic::{DiagnosticTag, NumberOrString},
55 path::get_relative_path,
@@ -969,22 +969,7 @@ impl Application {
969969 let mut errs = Vec::new();
970970
971971 // TODO: deduplicate with ctx.block_try_flush_writes
972− tokio::task::block_in_place(|| {
973− helix_lsp::block_on(async {
974− while let Some(save_event) = self.editor.save_queue.next().await {
975− match &save_event {
976− Ok(event) => {
977− let doc = doc_mut!(self.editor, &event.doc_id);
978− doc.set_last_saved_revision(event.revision);
979− }
980− Err(err) => {
981− log::error!("error saving document: {}", err);
982− }
983− };
984− // TODO: if is_err: break?
985− }
986− })
987− });
972+ tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()));
988973
989974 if let Err(err) = self
990975 .jobs
helix-term/src/commands/typed.rs+1−16
@@ -80,22 +80,7 @@ fn buffer_close_by_ids_impl(
8080 force: bool,
8181) -> anyhow::Result<()> {
8282 // TODO: deduplicate with ctx.block_try_flush_writes
83− tokio::task::block_in_place(|| {
84− helix_lsp::block_on(async {
85− while let Some(save_event) = editor.save_queue.next().await {
86− match &save_event {
87− Ok(event) => {
88− let doc = doc_mut!(editor, &event.doc_id);
89− doc.set_last_saved_revision(event.revision);
90− }
91− Err(err) => {
92− log::error!("error saving document: {}", err);
93− }
94− };
95− // TODO: if is_err: break?
96− }
97− })
98− });
83+ tokio::task::block_in_place(|| helix_lsp::block_on(editor.flush_writes()));
9984
10085 let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
10186 .iter()
helix-term/src/compositor.rs+1−17
@@ -1,4 +1,3 @@
1−use futures_util::StreamExt;
21// Each component declares it's own size constraints and gets fitted based on it's parent.
32// Q: how does this work with popups?
43// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
@@ -34,22 +33,7 @@ impl<'a> Context<'a> {
3433 pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
3534 tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?;
3635
37− tokio::task::block_in_place(|| {
38− helix_lsp::block_on(async {
39− while let Some(save_event) = self.editor.save_queue.next().await {
40− match &save_event {
41− Ok(event) => {
42− let doc = doc_mut!(self.editor, &event.doc_id);
43− doc.set_last_saved_revision(event.revision);
44− }
45− Err(err) => {
46− log::error!("error saving document: {}", err);
47− }
48− };
49− // TODO: if is_err: break?
50− }
51− })
52− });
36+ tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()));
5337
5438 Ok(())
5539 }
helix-view/src/editor.rs+15
@@ -1348,4 +1348,19 @@ impl Editor {
13481348 }
13491349 }
13501350 }
1351+
1352+ pub async fn flush_writes(&mut self) {
1353+ while let Some(save_event) = self.save_queue.next().await {
1354+ match &save_event {
1355+ Ok(event) => {
1356+ let doc = doc_mut!(self, &event.doc_id);
1357+ doc.set_last_saved_revision(event.revision);
1358+ }
1359+ Err(err) => {
1360+ log::error!("error saving document: {}", err);
1361+ }
1362+ };
1363+ // TODO: if is_err: break?
1364+ }
1365+ }
13511366}