Skip to content

Commit cd339a7

Browse files
committed
commands: skip code actions on auto save
Enables the `--no-format` flag for the write and write-all commands to also disable configured on save code actions.
1 parent 82c2dd7 commit cd339a7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

helix-term/src/commands/typed.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ fn exit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow:
8080
WriteOptions {
8181
force: false,
8282
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
83+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
8384
},
8485
)?;
8586
}
@@ -99,6 +100,7 @@ fn force_exit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> a
99100
WriteOptions {
100101
force: true,
101102
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
103+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
102104
},
103105
)?;
104106
}
@@ -420,7 +422,11 @@ fn write_impl(
420422
None
421423
};
422424

423-
let job = code_actions_on_save(cx, doc_id, fmt);
425+
let job = if options.code_actions {
426+
code_actions_on_save(cx, doc_id, fmt)
427+
} else {
428+
fmt
429+
};
424430

425431
if let Some(job) = job {
426432
cx.jobs.add(job);
@@ -496,6 +502,7 @@ fn insert_final_newline(doc: &mut Document, view_id: ViewId) {
496502
pub struct WriteOptions {
497503
pub force: bool,
498504
pub auto_format: bool,
505+
pub code_actions: bool,
499506
}
500507

501508
fn write(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow::Result<()> {
@@ -509,6 +516,7 @@ fn write(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow
509516
WriteOptions {
510517
force: false,
511518
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
519+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
512520
},
513521
)
514522
}
@@ -524,6 +532,7 @@ fn force_write(cx: &mut compositor::Context, args: Args, event: PromptEvent) ->
524532
WriteOptions {
525533
force: true,
526534
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
535+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
527536
},
528537
)
529538
}
@@ -543,6 +552,7 @@ fn write_buffer_close(
543552
WriteOptions {
544553
force: false,
545554
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
555+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
546556
},
547557
)?;
548558

@@ -565,6 +575,7 @@ fn force_write_buffer_close(
565575
WriteOptions {
566576
force: true,
567577
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
578+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
568579
},
569580
)?;
570581

@@ -753,6 +764,7 @@ fn write_quit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> a
753764
WriteOptions {
754765
force: false,
755766
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
767+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
756768
},
757769
)?;
758770
cx.block_try_flush_writes()?;
@@ -774,6 +786,7 @@ fn force_write_quit(
774786
WriteOptions {
775787
force: true,
776788
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
789+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
777790
},
778791
)?;
779792
cx.block_try_flush_writes()?;
@@ -818,6 +831,7 @@ pub struct WriteAllOptions {
818831
pub force: bool,
819832
pub write_scratch: bool,
820833
pub auto_format: bool,
834+
pub code_actions: bool,
821835
}
822836

823837
pub fn write_all_impl(
@@ -891,7 +905,11 @@ pub fn write_all_impl(
891905
None
892906
};
893907

894-
let job = code_actions_on_save(cx, doc_id, fmt);
908+
let job = if options.code_actions {
909+
code_actions_on_save(cx, doc_id, fmt)
910+
} else {
911+
fmt
912+
};
895913

896914
if let Some(job) = job {
897915
cx.jobs.add(job);
@@ -918,6 +936,7 @@ fn write_all(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> an
918936
force: false,
919937
write_scratch: true,
920938
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
939+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
921940
},
922941
)
923942
}
@@ -937,6 +956,7 @@ fn force_write_all(
937956
force: true,
938957
write_scratch: true,
939958
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
959+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
940960
},
941961
)
942962
}
@@ -955,6 +975,7 @@ fn write_all_quit(
955975
force: false,
956976
write_scratch: true,
957977
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
978+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
958979
},
959980
)?;
960981
quit_all_impl(cx, false)
@@ -974,6 +995,7 @@ fn force_write_all_quit(
974995
force: true,
975996
write_scratch: true,
976997
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
998+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
977999
},
9781000
);
9791001
quit_all_impl(cx, true)
@@ -1537,6 +1559,7 @@ fn update(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
15371559
WriteOptions {
15381560
force: false,
15391561
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
1562+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
15401563
},
15411564
)
15421565
} else {

helix-term/src/handlers/auto_save.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ fn request_auto_save(editor: &mut Editor) {
9191
force: false,
9292
write_scratch: false,
9393
auto_format: false,
94+
code_actions: false,
9495
};
9596

9697
if let Err(e) = commands::typed::write_all_impl(context, options) {

helix-term/src/ui/editor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ impl Component for EditorView {
15111511
force: false,
15121512
write_scratch: false,
15131513
auto_format: false,
1514+
code_actions: false,
15141515
};
15151516
if let Err(e) = commands::typed::write_all_impl(context, options) {
15161517
context.editor.set_error(format!("{}", e));

0 commit comments

Comments
 (0)