summaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorOmnikar2022-04-12 07:52:54 +0000
committerGitHub2022-04-12 07:52:54 +0000
commit660e0e44b2b6329c1d0af788d624dd5765c2acc6 (patch)
tree03a5e162612c5c2e3ebf62530baaab2d13e63da8 /helix-view/src
parentd5c086697896d87f034c1dbe0ae0ccbc71f37d2c (diff)
Add `:write!` to create nonexistent subdirectories (#1839)
* Make `:write` create nonexistent subdirectories Prompting as to whether this should take place remains a TODO. * Move subdirectory creation to new `w!` command
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 5d739af5..f4b4dc35 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -434,15 +434,16 @@ impl Document {
Some(fut)
}
- pub fn save(&mut self) -> impl Future<Output = Result<(), anyhow::Error>> {
- self.save_impl::<futures_util::future::Ready<_>>(None)
+ pub fn save(&mut self, force: bool) -> impl Future<Output = Result<(), anyhow::Error>> {
+ self.save_impl::<futures_util::future::Ready<_>>(None, force)
}
pub fn format_and_save(
&mut self,
formatting: Option<impl Future<Output = LspFormatting>>,
+ force: bool,
) -> impl Future<Output = anyhow::Result<()>> {
- self.save_impl(formatting)
+ self.save_impl(formatting, force)
}
// TODO: do we need some way of ensuring two save operations on the same doc can't run at once?
@@ -454,6 +455,7 @@ impl Document {
fn save_impl<F: Future<Output = LspFormatting>>(
&mut self,
formatting: Option<F>,
+ force: bool,
) -> impl Future<Output = Result<(), anyhow::Error>> {
// we clone and move text + path into the future so that we asynchronously save the current
// state without blocking any further edits.
@@ -475,7 +477,11 @@ impl Document {
if let Some(parent) = path.parent() {
// TODO: display a prompt asking the user if the directories should be created
if !parent.exists() {
- bail!("can't save file, parent directory does not exist");
+ if force {
+ std::fs::DirBuilder::new().recursive(true).create(parent)?;
+ } else {
+ bail!("can't save file, parent directory does not exist");
+ }
}
}