mirror of https://github.com/helix-editor/helix
minimize diff
A few edits here to minimize the overall (squashed) diff:
* Minimize borrow-checker-satisfying changes in write_impl,
write_all_impl. We just need to "refresh" the bindings of `doc` and
`view` It's nice to avoid extra blocks for the `&mut` bindings since
they unnecessarily add indentation/nesting.
* Factor out the `Result<Vec<_>, _>` early in `Document::format`: this
avoids changing the indentation for the rest of the block.
With these changes the stat (git diff --stat 9f3b193743
) lowers from
+128,-82 to +51,-10.
Also there's a style change here to prefer `use`-ing the
`crate::expansion` module so it's clearer where the `expand` function
comes from.
pull/13429/head
parent
3763fc3c54
commit
3d8a63e072
|
@ -324,7 +324,6 @@ fn buffer_previous(
|
|||
fn write_impl(cx: &mut compositor::Context, path: Option<&str>, force: bool) -> anyhow::Result<()> {
|
||||
let config = cx.editor.config();
|
||||
let jobs = &mut cx.jobs;
|
||||
{
|
||||
let (view, doc) = current!(cx.editor);
|
||||
|
||||
if doc.trim_trailing_whitespace() {
|
||||
|
@ -339,7 +338,6 @@ fn write_impl(cx: &mut compositor::Context, path: Option<&str>, force: bool) ->
|
|||
|
||||
// Save an undo checkpoint for any outstanding changes.
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
|
||||
let (view, doc) = current_ref!(cx.editor);
|
||||
let fmt = if config.auto_format {
|
||||
|
@ -738,7 +736,6 @@ pub fn write_all_impl(
|
|||
.collect();
|
||||
|
||||
for (doc_id, target_view) in saves {
|
||||
{
|
||||
let doc = doc_mut!(cx.editor, &doc_id);
|
||||
let view = view_mut!(cx.editor, target_view);
|
||||
|
||||
|
@ -754,10 +751,9 @@ pub fn write_all_impl(
|
|||
|
||||
// Save an undo checkpoint for any outstanding changes.
|
||||
doc.append_changes_to_history(view);
|
||||
}
|
||||
|
||||
let doc = doc!(cx.editor, &doc_id);
|
||||
let fmt = if options.auto_format && config.auto_format {
|
||||
let doc = doc!(cx.editor, &doc_id);
|
||||
doc.auto_format(cx.editor).map(|fmt| {
|
||||
let callback = make_format_callback(
|
||||
doc_id,
|
||||
|
|
|
@ -5,7 +5,6 @@ use futures_util::future::BoxFuture;
|
|||
use futures_util::FutureExt;
|
||||
use helix_core::auto_pairs::AutoPairs;
|
||||
use helix_core::chars::char_is_word;
|
||||
|
||||
use helix_core::command_line::Token;
|
||||
use helix_core::diagnostic::DiagnosticProvider;
|
||||
use helix_core::doc_formatter::TextFormat;
|
||||
|
@ -44,10 +43,10 @@ use helix_core::{
|
|||
ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction,
|
||||
};
|
||||
|
||||
use crate::expansion::expand;
|
||||
use crate::{
|
||||
editor::Config,
|
||||
events::{DocumentDidChange, SelectionDidChange},
|
||||
expansion,
|
||||
view::ViewPosition,
|
||||
DocumentId, Editor, Theme, View, ViewId,
|
||||
};
|
||||
|
@ -823,22 +822,26 @@ impl Document {
|
|||
process.current_dir(doc_dir);
|
||||
}
|
||||
|
||||
let fmt_args = fmt_args
|
||||
let args = match fmt_args
|
||||
.iter()
|
||||
.map(|content| expand(editor, Token::expand(content)))
|
||||
.collect::<anyhow::Result<Vec<_>>>();
|
||||
.map(|content| expansion::expand(editor, Token::expand(content)))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
{
|
||||
Ok(args) => args,
|
||||
Err(err) => {
|
||||
log::error!("Failed to expand formatter arguments: {err}");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
match fmt_args {
|
||||
Ok(fmt_args) => {
|
||||
process
|
||||
.args(fmt_args.iter().map(Cow::as_ref))
|
||||
.args(args.iter().map(AsRef::as_ref))
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
|
||||
let formatting_future = async move {
|
||||
let mut process =
|
||||
process
|
||||
let mut process = process
|
||||
.spawn()
|
||||
.map_err(|e| FormatterError::SpawningFailed {
|
||||
command: fmt_cmd.to_string_lossy().into(),
|
||||
|
@ -858,8 +861,7 @@ impl Document {
|
|||
process.wait_with_output(),
|
||||
};
|
||||
let _ = input_result.map_err(|_| FormatterError::BrokenStdin)?;
|
||||
let output =
|
||||
output_result.map_err(|_| FormatterError::WaitForOutputFailed)?;
|
||||
let output = output_result.map_err(|_| FormatterError::WaitForOutputFailed)?;
|
||||
|
||||
if !output.status.success() {
|
||||
if !output.stderr.is_empty() {
|
||||
|
@ -882,9 +884,6 @@ impl Document {
|
|||
Ok(helix_core::diff::compare_ropes(&text, &Rope::from(str)))
|
||||
};
|
||||
return Some(formatting_future.boxed());
|
||||
}
|
||||
Err(e) => log::error!("{e}"),
|
||||
}
|
||||
};
|
||||
|
||||
let text = self.text.clone();
|
||||
|
|
Loading…
Reference in New Issue