Skip to content

Commit f835a1a

Browse files
committed
commands: Skip code actions on save with no-format flag
Same as with auto-format, auto save will not trigger code actions
1 parent b2dd391 commit f835a1a

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

helix-term/src/commands/typed.rs

Lines changed: 21 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
}
@@ -398,7 +400,9 @@ fn write_impl(
398400
// Save an undo checkpoint for any outstanding changes.
399401
doc.append_changes_to_history(view);
400402

401-
code_actions_on_save(cx, &doc_id);
403+
if options.code_actions {
404+
code_actions_on_save(cx, &doc_id);
405+
}
402406

403407
let (view, doc) = current_ref!(cx.editor);
404408
let fmt = if config.auto_format && options.auto_format {
@@ -489,6 +493,7 @@ fn insert_final_newline(doc: &mut Document, view_id: ViewId) {
489493
pub struct WriteOptions {
490494
pub force: bool,
491495
pub auto_format: bool,
496+
pub code_actions: bool,
492497
}
493498

494499
fn write(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow::Result<()> {
@@ -502,6 +507,7 @@ fn write(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow
502507
WriteOptions {
503508
force: false,
504509
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
510+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
505511
},
506512
)
507513
}
@@ -517,6 +523,7 @@ fn force_write(cx: &mut compositor::Context, args: Args, event: PromptEvent) ->
517523
WriteOptions {
518524
force: true,
519525
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
526+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
520527
},
521528
)
522529
}
@@ -536,6 +543,7 @@ fn write_buffer_close(
536543
WriteOptions {
537544
force: false,
538545
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
546+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
539547
},
540548
)?;
541549

@@ -558,6 +566,7 @@ fn force_write_buffer_close(
558566
WriteOptions {
559567
force: true,
560568
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
569+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
561570
},
562571
)?;
563572

@@ -746,6 +755,7 @@ fn write_quit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> a
746755
WriteOptions {
747756
force: false,
748757
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
758+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
749759
},
750760
)?;
751761
cx.block_try_flush_writes()?;
@@ -767,6 +777,7 @@ fn force_write_quit(
767777
WriteOptions {
768778
force: true,
769779
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
780+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
770781
},
771782
)?;
772783
cx.block_try_flush_writes()?;
@@ -811,6 +822,7 @@ pub struct WriteAllOptions {
811822
pub force: bool,
812823
pub write_scratch: bool,
813824
pub auto_format: bool,
825+
pub code_actions: bool,
814826
}
815827

816828
pub fn write_all_impl(
@@ -861,7 +873,9 @@ pub fn write_all_impl(
861873
// Save an undo checkpoint for any outstanding changes.
862874
doc.append_changes_to_history(view);
863875

864-
code_actions_on_save(cx, &doc_id);
876+
if options.code_actions {
877+
code_actions_on_save(cx, &doc_id);
878+
}
865879

866880
let fmt = if options.auto_format && config.auto_format {
867881
let doc = doc!(cx.editor, &doc_id);
@@ -903,6 +917,7 @@ fn write_all(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> an
903917
force: false,
904918
write_scratch: true,
905919
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
920+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
906921
},
907922
)
908923
}
@@ -922,6 +937,7 @@ fn force_write_all(
922937
force: true,
923938
write_scratch: true,
924939
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
940+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
925941
},
926942
)
927943
}
@@ -940,6 +956,7 @@ fn write_all_quit(
940956
force: false,
941957
write_scratch: true,
942958
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
959+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
943960
},
944961
)?;
945962
quit_all_impl(cx, false)
@@ -959,6 +976,7 @@ fn force_write_all_quit(
959976
force: true,
960977
write_scratch: true,
961978
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
979+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
962980
},
963981
);
964982
quit_all_impl(cx, true)
@@ -1522,6 +1540,7 @@ fn update(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
15221540
WriteOptions {
15231541
force: false,
15241542
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
1543+
code_actions: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
15251544
},
15261545
)
15271546
} 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
@@ -1515,6 +1515,7 @@ impl Component for EditorView {
15151515
force: false,
15161516
write_scratch: false,
15171517
auto_format: false,
1518+
code_actions: false,
15181519
};
15191520
if let Err(e) = commands::typed::write_all_impl(context, options) {
15201521
context.editor.set_error(format!("{}", e));

0 commit comments

Comments
 (0)