Skip to content

Commit

Permalink
Uses unwrap_or when setting formatting process directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Gonnella committed Dec 27, 2024
1 parent 75c8980 commit 2c8fe9f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,13 @@ impl Document {
use std::process::Stdio;
let text = self.text().clone();
let mut process = tokio::process::Command::new(&fmt_cmd);
if let Some(path) = self.path.clone() {
if let Some(parent) = path.parent() {
process.current_dir(parent);
}
}
let cwd = std::env::current_dir().unwrap_or(PathBuf::from("."));
let file_path = cwd.join(self.display_name().to_string());
let doc_path = self.path.clone().unwrap_or(PathBuf::from(file_path));
let doc_dir = doc_path.parent().unwrap_or(cwd.as_path());

process
.current_dir(doc_dir)
.args(fmt_args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand Down

0 comments on commit 2c8fe9f

Please sign in to comment.