Rename doc save event names to past tense
This commit is contained in:
parent
6cffc7f05d
commit
f82a551b98
4 changed files with 19 additions and 18 deletions
|
@ -9,7 +9,7 @@ use helix_core::{
|
||||||
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
|
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
|
||||||
use helix_view::{
|
use helix_view::{
|
||||||
align_view,
|
align_view,
|
||||||
document::DocumentSaveEventResult,
|
document::DocumentSavedEventResult,
|
||||||
editor::{ConfigEvent, EditorEvent},
|
editor::{ConfigEvent, EditorEvent},
|
||||||
theme,
|
theme,
|
||||||
tree::Layout,
|
tree::Layout,
|
||||||
|
@ -431,7 +431,7 @@ impl Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_document_write(&mut self, doc_save_event: DocumentSaveEventResult) {
|
pub fn handle_document_write(&mut self, doc_save_event: DocumentSavedEventResult) {
|
||||||
if let Err(err) = doc_save_event {
|
if let Err(err) = doc_save_event {
|
||||||
self.editor.set_error(err.to_string());
|
self.editor.set_error(err.to_string());
|
||||||
return;
|
return;
|
||||||
|
@ -485,7 +485,7 @@ impl Application {
|
||||||
log::debug!("received editor event: {:?}", event);
|
log::debug!("received editor event: {:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
EditorEvent::DocumentSave(event) => {
|
EditorEvent::DocumentSaved(event) => {
|
||||||
self.handle_document_write(event);
|
self.handle_document_write(event);
|
||||||
self.render();
|
self.render();
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,7 @@ impl Jobs {
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
log::debug!("waiting on jobs...");
|
log::debug!("waiting on jobs...");
|
||||||
let mut wait_futures = std::mem::take(&mut self.wait_futures);
|
let mut wait_futures = std::mem::take(&mut self.wait_futures);
|
||||||
|
|
||||||
while let (Some(job), tail) = wait_futures.into_future().await {
|
while let (Some(job), tail) = wait_futures.into_future().await {
|
||||||
match job {
|
match job {
|
||||||
Ok(callback) => {
|
Ok(callback) => {
|
||||||
|
|
|
@ -89,14 +89,14 @@ impl Serialize for Mode {
|
||||||
|
|
||||||
/// A snapshot of the text of a document that we want to write out to disk
|
/// A snapshot of the text of a document that we want to write out to disk
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DocumentSaveEvent {
|
pub struct DocumentSavedEvent {
|
||||||
pub revision: usize,
|
pub revision: usize,
|
||||||
pub doc_id: DocumentId,
|
pub doc_id: DocumentId,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type DocumentSaveEventResult = Result<DocumentSaveEvent, anyhow::Error>;
|
pub type DocumentSavedEventResult = Result<DocumentSavedEvent, anyhow::Error>;
|
||||||
pub type DocumentSaveEventFuture = BoxFuture<'static, DocumentSaveEventResult>;
|
pub type DocumentSavedEventFuture = BoxFuture<'static, DocumentSavedEventResult>;
|
||||||
|
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
pub(crate) id: DocumentId,
|
pub(crate) id: DocumentId,
|
||||||
|
@ -133,9 +133,9 @@ pub struct Document {
|
||||||
last_saved_revision: usize,
|
last_saved_revision: usize,
|
||||||
version: i32, // should be usize?
|
version: i32, // should be usize?
|
||||||
pub(crate) modified_since_accessed: bool,
|
pub(crate) modified_since_accessed: bool,
|
||||||
save_sender: Option<UnboundedSender<DocumentSaveEventFuture>>,
|
save_sender: Option<UnboundedSender<DocumentSavedEventFuture>>,
|
||||||
save_receiver: Option<UnboundedReceiver<DocumentSaveEventFuture>>,
|
save_receiver: Option<UnboundedReceiver<DocumentSavedEventFuture>>,
|
||||||
current_save: Arc<Mutex<Option<DocumentSaveEventFuture>>>,
|
current_save: Arc<Mutex<Option<DocumentSavedEventFuture>>>,
|
||||||
|
|
||||||
diagnostics: Vec<Diagnostic>,
|
diagnostics: Vec<Diagnostic>,
|
||||||
language_server: Option<Arc<helix_lsp::Client>>,
|
language_server: Option<Arc<helix_lsp::Client>>,
|
||||||
|
@ -616,7 +616,7 @@ impl Document {
|
||||||
let mut file = File::create(&path).await?;
|
let mut file = File::create(&path).await?;
|
||||||
to_writer(&mut file, encoding, &text).await?;
|
to_writer(&mut file, encoding, &text).await?;
|
||||||
|
|
||||||
let event = DocumentSaveEvent {
|
let event = DocumentSavedEvent {
|
||||||
revision: current_rev,
|
revision: current_rev,
|
||||||
doc_id,
|
doc_id,
|
||||||
path,
|
path,
|
||||||
|
@ -643,11 +643,11 @@ impl Document {
|
||||||
.map_err(|err| anyhow!("failed to send save event: {}", err))
|
.map_err(|err| anyhow!("failed to send save event: {}", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn await_save(&mut self) -> Option<DocumentSaveEventResult> {
|
pub async fn await_save(&mut self) -> Option<DocumentSavedEventResult> {
|
||||||
self.await_save_impl(true).await
|
self.await_save_impl(true).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
|
async fn await_save_impl(&mut self, block: bool) -> Option<DocumentSavedEventResult> {
|
||||||
let mut current_save = self.current_save.lock().await;
|
let mut current_save = self.current_save.lock().await;
|
||||||
if let Some(ref mut save) = *current_save {
|
if let Some(ref mut save) = *current_save {
|
||||||
log::trace!("reawaiting save of '{:?}'", self.path());
|
log::trace!("reawaiting save of '{:?}'", self.path());
|
||||||
|
@ -698,11 +698,11 @@ impl Document {
|
||||||
|
|
||||||
/// Flushes the queue of pending writes. If any fail,
|
/// Flushes the queue of pending writes. If any fail,
|
||||||
/// it stops early before emptying the rest of the queue.
|
/// it stops early before emptying the rest of the queue.
|
||||||
pub async fn try_flush_saves(&mut self) -> Option<DocumentSaveEventResult> {
|
pub async fn try_flush_saves(&mut self) -> Option<DocumentSavedEventResult> {
|
||||||
self.flush_saves_impl(false).await
|
self.flush_saves_impl(false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn flush_saves_impl(&mut self, block: bool) -> Option<DocumentSaveEventResult> {
|
async fn flush_saves_impl(&mut self, block: bool) -> Option<DocumentSavedEventResult> {
|
||||||
let mut final_result = None;
|
let mut final_result = None;
|
||||||
|
|
||||||
while let Some(save_event) = self.await_save_impl(block).await {
|
while let Some(save_event) = self.await_save_impl(block).await {
|
||||||
|
@ -734,7 +734,7 @@ impl Document {
|
||||||
/// Prepares the Document for being closed by stopping any new writes
|
/// Prepares the Document for being closed by stopping any new writes
|
||||||
/// and flushing through the queue of pending writes. If any fail,
|
/// and flushing through the queue of pending writes. If any fail,
|
||||||
/// it stops early before emptying the rest of the queue.
|
/// it stops early before emptying the rest of the queue.
|
||||||
pub async fn close(&mut self) -> Option<DocumentSaveEventResult> {
|
pub async fn close(&mut self) -> Option<DocumentSavedEventResult> {
|
||||||
if self.save_sender.is_some() {
|
if self.save_sender.is_some() {
|
||||||
self.save_sender.take();
|
self.save_sender.take();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
clipboard::{get_clipboard_provider, ClipboardProvider},
|
clipboard::{get_clipboard_provider, ClipboardProvider},
|
||||||
document::{DocumentSaveEventResult, Mode},
|
document::{DocumentSavedEventResult, Mode},
|
||||||
graphics::{CursorKind, Rect},
|
graphics::{CursorKind, Rect},
|
||||||
info::Info,
|
info::Info,
|
||||||
input::KeyEvent,
|
input::KeyEvent,
|
||||||
|
@ -691,7 +691,7 @@ pub struct Editor {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum EditorEvent {
|
pub enum EditorEvent {
|
||||||
DocumentSave(DocumentSaveEventResult),
|
DocumentSaved(DocumentSavedEventResult),
|
||||||
ConfigEvent(ConfigEvent),
|
ConfigEvent(ConfigEvent),
|
||||||
LanguageServerMessage((usize, Call)),
|
LanguageServerMessage((usize, Call)),
|
||||||
DebuggerEvent(dap::Payload),
|
DebuggerEvent(dap::Payload),
|
||||||
|
@ -1317,7 +1317,7 @@ impl Editor {
|
||||||
biased;
|
biased;
|
||||||
|
|
||||||
Some(Some(event)) = saves.next() => {
|
Some(Some(event)) = saves.next() => {
|
||||||
EditorEvent::DocumentSave(event)
|
EditorEvent::DocumentSaved(event)
|
||||||
}
|
}
|
||||||
Some(config_event) = self.config_events.1.recv() => {
|
Some(config_event) = self.config_events.1.recv() => {
|
||||||
EditorEvent::ConfigEvent(config_event)
|
EditorEvent::ConfigEvent(config_event)
|
||||||
|
|
Loading…
Reference in a new issue