summaryrefslogtreecommitdiff
path: root/helix-term/src/application.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-04-24 19:33:43 +0000
committerSkyler Hawthorne2022-10-19 02:31:38 +0000
commit83b6042b97d13fca751e3d5d0c32f04e3ad04c9a (patch)
tree42fb0367fcd09868371687e3ccbe27abf2de4762 /helix-term/src/application.rs
parenta5a93182cd5ccf88bc95b68044aa05d746ded35e (diff)
fix(write): do not set new path on document until write succeeds
If a document is written with a new path, currently, in the event that the write fails, the document still gets its path changed. This fixes it so that the path is not updated unless the write succeeds.
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r--helix-term/src/application.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 2c1047da..0640de3c 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -3,6 +3,7 @@ use futures_util::Stream;
use helix_core::{
config::{default_syntax_loader, user_syntax_loader},
diagnostic::{DiagnosticTag, NumberOrString},
+ path::get_relative_path,
pos_at_coords, syntax, Selection,
};
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
@@ -489,17 +490,26 @@ impl Application {
);
doc.set_last_saved_revision(doc_save_event.revision);
+
let lines = doc.text().len_lines();
let bytes = doc.text().len_bytes();
- let path_str = doc
- .path()
- .expect("document written without path")
- .to_string_lossy()
- .into_owned();
-
- self.editor
- .set_status(format!("'{}' written, {}L {}B", path_str, lines, bytes));
+ if let Err(err) = doc.set_path(Some(&doc_save_event.path)) {
+ log::error!(
+ "error setting path for doc '{:?}': {}",
+ doc.path(),
+ err.to_string(),
+ );
+ self.editor.set_error(err.to_string());
+ } else {
+ // TODO: fix being overwritten by lsp
+ self.editor.set_status(format!(
+ "'{}' written, {}L {}B",
+ get_relative_path(&doc_save_event.path).to_string_lossy(),
+ lines,
+ bytes
+ ));
+ }
}
pub fn handle_terminal_events(&mut self, event: Result<CrosstermEvent, crossterm::ErrorKind>) {