Skip to content

Commit 340154a

Browse files
committed
commands: add no-code-actions flag to write and write-all
Same as with auto-format, auto save will not trigger code actions
1 parent 17bbdba commit 340154a

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

helix-term/src/commands/typed.rs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ fn write_impl(
360360
// Save an undo checkpoint for any outstanding changes.
361361
doc.append_changes_to_history(view);
362362

363-
code_actions_on_save(cx, &doc_id);
363+
if options.code_actions {
364+
code_actions_on_save(cx, &doc_id);
365+
}
364366

365367
let (view, doc) = current_ref!(cx.editor);
366368
let fmt = if config.auto_format && options.auto_format {
@@ -451,6 +453,7 @@ fn insert_final_newline(doc: &mut Document, view_id: ViewId) {
451453
pub struct WriteOptions {
452454
pub force: bool,
453455
pub auto_format: bool,
456+
pub code_actions: bool,
454457
}
455458

456459
fn write(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow::Result<()> {
@@ -464,6 +467,7 @@ fn write(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow
464467
WriteOptions {
465468
force: false,
466469
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
470+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
467471
},
468472
)
469473
}
@@ -479,6 +483,7 @@ fn force_write(cx: &mut compositor::Context, args: Args, event: PromptEvent) ->
479483
WriteOptions {
480484
force: true,
481485
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
486+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
482487
},
483488
)
484489
}
@@ -498,6 +503,7 @@ fn write_buffer_close(
498503
WriteOptions {
499504
force: false,
500505
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
506+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
501507
},
502508
)?;
503509

@@ -520,6 +526,7 @@ fn force_write_buffer_close(
520526
WriteOptions {
521527
force: true,
522528
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
529+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
523530
},
524531
)?;
525532

@@ -708,6 +715,7 @@ fn write_quit(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> a
708715
WriteOptions {
709716
force: false,
710717
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
718+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
711719
},
712720
)?;
713721
cx.block_try_flush_writes()?;
@@ -729,6 +737,7 @@ fn force_write_quit(
729737
WriteOptions {
730738
force: true,
731739
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
740+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
732741
},
733742
)?;
734743
cx.block_try_flush_writes()?;
@@ -773,6 +782,7 @@ pub struct WriteAllOptions {
773782
pub force: bool,
774783
pub write_scratch: bool,
775784
pub auto_format: bool,
785+
pub code_actions: bool,
776786
}
777787

778788
pub fn write_all_impl(
@@ -823,7 +833,9 @@ pub fn write_all_impl(
823833
// Save an undo checkpoint for any outstanding changes.
824834
doc.append_changes_to_history(view);
825835

826-
code_actions_on_save(cx, &doc_id);
836+
if options.code_actions {
837+
code_actions_on_save(cx, &doc_id);
838+
}
827839

828840
let fmt = if options.auto_format && config.auto_format {
829841
let doc = doc!(cx.editor, &doc_id);
@@ -865,6 +877,7 @@ fn write_all(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> an
865877
force: false,
866878
write_scratch: true,
867879
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
880+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
868881
},
869882
)
870883
}
@@ -884,6 +897,7 @@ fn force_write_all(
884897
force: true,
885898
write_scratch: true,
886899
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
900+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
887901
},
888902
)
889903
}
@@ -902,6 +916,7 @@ fn write_all_quit(
902916
force: false,
903917
write_scratch: true,
904918
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
919+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
905920
},
906921
)?;
907922
quit_all_impl(cx, false)
@@ -921,6 +936,7 @@ fn force_write_all_quit(
921936
force: true,
922937
write_scratch: true,
923938
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
939+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
924940
},
925941
);
926942
quit_all_impl(cx, true)
@@ -1484,6 +1500,7 @@ fn update(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
14841500
WriteOptions {
14851501
force: false,
14861502
auto_format: !args.has_flag(WRITE_NO_FORMAT_FLAG.name),
1503+
code_actions: !args.has_flag(WRITE_NO_CODE_ACTIONS_FLAG.name),
14871504
},
14881505
)
14891506
} else {
@@ -2681,6 +2698,12 @@ const WRITE_NO_FORMAT_FLAG: Flag = Flag {
26812698
..Flag::DEFAULT
26822699
};
26832700

2701+
const WRITE_NO_CODE_ACTIONS_FLAG: Flag = Flag {
2702+
name: "no-code-actions",
2703+
doc: "skip code actions on save",
2704+
..Flag::DEFAULT
2705+
};
2706+
26842707
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
26852708
TypableCommand {
26862709
name: "quit",
@@ -2805,7 +2828,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
28052828
completer: CommandCompleter::positional(&[completers::filename]),
28062829
signature: Signature {
28072830
positionals: (0, Some(1)),
2808-
flags: &[WRITE_NO_FORMAT_FLAG],
2831+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
28092832
..Signature::DEFAULT
28102833
},
28112834
},
@@ -2817,7 +2840,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
28172840
completer: CommandCompleter::positional(&[completers::filename]),
28182841
signature: Signature {
28192842
positionals: (0, Some(1)),
2820-
flags: &[WRITE_NO_FORMAT_FLAG],
2843+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
28212844
..Signature::DEFAULT
28222845
},
28232846
},
@@ -2829,7 +2852,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
28292852
completer: CommandCompleter::positional(&[completers::filename]),
28302853
signature: Signature {
28312854
positionals: (0, Some(1)),
2832-
flags: &[WRITE_NO_FORMAT_FLAG],
2855+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
28332856
..Signature::DEFAULT
28342857
},
28352858
},
@@ -2841,7 +2864,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
28412864
completer: CommandCompleter::positional(&[completers::filename]),
28422865
signature: Signature {
28432866
positionals: (0, Some(1)),
2844-
flags: &[WRITE_NO_FORMAT_FLAG],
2867+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
28452868
..Signature::DEFAULT
28462869
},
28472870
},
@@ -2922,7 +2945,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29222945
completer: CommandCompleter::positional(&[completers::filename]),
29232946
signature: Signature {
29242947
positionals: (0, Some(1)),
2925-
flags: &[WRITE_NO_FORMAT_FLAG],
2948+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
29262949
..Signature::DEFAULT
29272950
},
29282951
},
@@ -2934,7 +2957,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29342957
completer: CommandCompleter::positional(&[completers::filename]),
29352958
signature: Signature {
29362959
positionals: (0, Some(1)),
2937-
flags: &[WRITE_NO_FORMAT_FLAG],
2960+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
29382961
..Signature::DEFAULT
29392962
},
29402963
},
@@ -2946,7 +2969,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29462969
completer: CommandCompleter::none(),
29472970
signature: Signature {
29482971
positionals: (0, Some(0)),
2949-
flags: &[WRITE_NO_FORMAT_FLAG],
2972+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
29502973
..Signature::DEFAULT
29512974
},
29522975
},
@@ -2958,7 +2981,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29582981
completer: CommandCompleter::none(),
29592982
signature: Signature {
29602983
positionals: (0, Some(0)),
2961-
flags: &[WRITE_NO_FORMAT_FLAG],
2984+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
29622985
..Signature::DEFAULT
29632986
},
29642987
},
@@ -2970,7 +2993,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29702993
completer: CommandCompleter::none(),
29712994
signature: Signature {
29722995
positionals: (0, Some(0)),
2973-
flags: &[WRITE_NO_FORMAT_FLAG],
2996+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
29742997
..Signature::DEFAULT
29752998
},
29762999
},
@@ -2982,7 +3005,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
29823005
completer: CommandCompleter::none(),
29833006
signature: Signature {
29843007
positionals: (0, Some(0)),
2985-
flags: &[WRITE_NO_FORMAT_FLAG],
3008+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
29863009
..Signature::DEFAULT
29873010
},
29883011
},
@@ -3247,7 +3270,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
32473270
completer: CommandCompleter::none(),
32483271
signature: Signature {
32493272
positionals: (0, Some(0)),
3250-
flags: &[WRITE_NO_FORMAT_FLAG],
3273+
flags: &[WRITE_NO_FORMAT_FLAG, WRITE_NO_CODE_ACTIONS_FLAG],
32513274
..Signature::DEFAULT
32523275
},
32533276
},

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)