Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run formatter from Document directory #12315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,13 @@ impl Document {
use std::process::Stdio;
let text = self.text().clone();
let mut process = tokio::process::Command::new(&fmt_cmd);
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(file_path);
Comment on lines +765 to +766
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unwrap_or_else(|| cwd.join(self.display_name().to_string()); to avoid the heap allocation on the Some branch.

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
Loading