Deduplicate flush_writes

pull/2267/head
Blaž Hrastnik 2 years ago committed by Skyler Hawthorne
parent 30c93994b5
commit b0212b3611

@ -1,5 +1,5 @@
use arc_swap::{access::Map, ArcSwap}; use arc_swap::{access::Map, ArcSwap};
use futures_util::{Stream, StreamExt}; use futures_util::Stream;
use helix_core::{ use helix_core::{
diagnostic::{DiagnosticTag, NumberOrString}, diagnostic::{DiagnosticTag, NumberOrString},
path::get_relative_path, path::get_relative_path,
@ -969,22 +969,7 @@ impl Application {
let mut errs = Vec::new(); let mut errs = Vec::new();
// TODO: deduplicate with ctx.block_try_flush_writes // TODO: deduplicate with ctx.block_try_flush_writes
tokio::task::block_in_place(|| { tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()));
helix_lsp::block_on(async {
while let Some(save_event) = self.editor.save_queue.next().await {
match &save_event {
Ok(event) => {
let doc = doc_mut!(self.editor, &event.doc_id);
doc.set_last_saved_revision(event.revision);
}
Err(err) => {
log::error!("error saving document: {}", err);
}
};
// TODO: if is_err: break?
}
})
});
if let Err(err) = self if let Err(err) = self
.jobs .jobs

@ -80,22 +80,7 @@ fn buffer_close_by_ids_impl(
force: bool, force: bool,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
// TODO: deduplicate with ctx.block_try_flush_writes // TODO: deduplicate with ctx.block_try_flush_writes
tokio::task::block_in_place(|| { tokio::task::block_in_place(|| helix_lsp::block_on(editor.flush_writes()));
helix_lsp::block_on(async {
while let Some(save_event) = editor.save_queue.next().await {
match &save_event {
Ok(event) => {
let doc = doc_mut!(editor, &event.doc_id);
doc.set_last_saved_revision(event.revision);
}
Err(err) => {
log::error!("error saving document: {}", err);
}
};
// TODO: if is_err: break?
}
})
});
let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids let (modified_ids, modified_names): (Vec<_>, Vec<_>) = doc_ids
.iter() .iter()

@ -1,4 +1,3 @@
use futures_util::StreamExt;
// Each component declares it's own size constraints and gets fitted based on it's parent. // Each component declares it's own size constraints and gets fitted based on it's parent.
// Q: how does this work with popups? // Q: how does this work with popups?
// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>) // cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
@ -34,22 +33,7 @@ impl<'a> Context<'a> {
pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> { pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> {
tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?; tokio::task::block_in_place(|| helix_lsp::block_on(self.jobs.finish(self.editor, None)))?;
tokio::task::block_in_place(|| { tokio::task::block_in_place(|| helix_lsp::block_on(self.editor.flush_writes()));
helix_lsp::block_on(async {
while let Some(save_event) = self.editor.save_queue.next().await {
match &save_event {
Ok(event) => {
let doc = doc_mut!(self.editor, &event.doc_id);
doc.set_last_saved_revision(event.revision);
}
Err(err) => {
log::error!("error saving document: {}", err);
}
};
// TODO: if is_err: break?
}
})
});
Ok(()) Ok(())
} }

@ -1348,4 +1348,19 @@ impl Editor {
} }
} }
} }
pub async fn flush_writes(&mut self) {
while let Some(save_event) = self.save_queue.next().await {
match &save_event {
Ok(event) => {
let doc = doc_mut!(self, &event.doc_id);
doc.set_last_saved_revision(event.revision);
}
Err(err) => {
log::error!("error saving document: {}", err);
}
};
// TODO: if is_err: break?
}
}
} }

Loading…
Cancel
Save