From eaea782fe9fbb9dd534aea5dd9ad79250c5ccf2c Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sun, 19 Feb 2023 20:41:30 +0100 Subject: [PATCH 1/5] (renaming) Context -> CompositorContext --- helix-term/src/application.rs | 6 +- helix-term/src/commands.rs | 6 +- helix-term/src/commands/dap.rs | 2 +- helix-term/src/commands/lsp.rs | 2 +- helix-term/src/commands/typed.rs | 168 +++++++++++++++---------------- helix-term/src/compositor.rs | 16 +-- helix-term/src/ui/completion.rs | 6 +- helix-term/src/ui/editor.rs | 8 +- helix-term/src/ui/info.rs | 4 +- helix-term/src/ui/lsp.rs | 4 +- helix-term/src/ui/markdown.rs | 4 +- helix-term/src/ui/menu.rs | 6 +- helix-term/src/ui/mod.rs | 6 +- helix-term/src/ui/overlay.rs | 6 +- helix-term/src/ui/picker.rs | 26 ++--- helix-term/src/ui/popup.rs | 8 +- helix-term/src/ui/prompt.rs | 18 ++-- helix-term/src/ui/text.rs | 4 +- 18 files changed, 150 insertions(+), 150 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index c8e8ecb1ae61..41ea7caa1c87 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -278,7 +278,7 @@ impl Application { } async fn render(&mut self) { - let mut cx = crate::compositor::Context { + let mut cx = crate::compositor::CompositorContext { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, @@ -495,7 +495,7 @@ impl Application { } pub async fn handle_idle_timeout(&mut self) { - let mut cx = crate::compositor::Context { + let mut cx = crate::compositor::CompositorContext { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, @@ -615,7 +615,7 @@ impl Application { &mut self, event: Result, ) { - let mut cx = crate::compositor::Context { + let mut cx = crate::compositor::CompositorContext { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index fb55ca2a8e72..f3c0f833c07c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -172,7 +172,7 @@ impl MappableCommand { Self::Typable { name, args, doc: _ } => { let args: Vec> = args.iter().map(Cow::from).collect(); if let Some(command) = typed::TYPABLE_COMMAND_MAP.get(name.as_str()) { - let mut cx = compositor::Context { + let mut cx = compositor::CompositorContext { editor: cx.editor, jobs: cx.jobs, scroll: None, @@ -2609,7 +2609,7 @@ impl ui::menu::Item for MappableCommand { pub fn command_palette(cx: &mut Context) { cx.callback = Some(Box::new( - move |compositor: &mut Compositor, cx: &mut compositor::Context| { + move |compositor: &mut Compositor, cx: &mut compositor::CompositorContext| { let keymap = compositor.find::().unwrap().keymaps.map() [&cx.editor.mode] .reverse_map(); @@ -5052,7 +5052,7 @@ async fn shell_impl_async( Ok((tendril, output.status.success())) } -fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) { +fn shell(cx: &mut compositor::CompositorContext, cmd: &str, behavior: &ShellBehavior) { let pipe = match behavior { ShellBehavior::Replace | ShellBehavior::Ignore => true, ShellBehavior::Insert | ShellBehavior::Append => false, diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index b3166e395d90..bc69c3c82124 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -130,7 +130,7 @@ fn dap_callback( } pub fn dap_start_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, name: Option<&str>, socket: Option, params: Option>>, diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 3b94c9bd5558..1dd74aba3c5c 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1249,7 +1249,7 @@ pub fn rename_symbol(cx: &mut Context) { prefill, None, ui::completers::none, - move |cx: &mut compositor::Context, input: &str, event: PromptEvent| { + move |cx: &mut compositor::CompositorContext, input: &str, event: PromptEvent| { if event != PromptEvent::Validate { return; } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index b0fd18a76b79..21026136b770 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -17,11 +17,11 @@ pub struct TypableCommand { pub aliases: &'static [&'static str], pub doc: &'static str, // params, flags, helper, completer - pub fun: fn(&mut compositor::Context, &[Cow], PromptEvent) -> anyhow::Result<()>, + pub fun: fn(&mut compositor::CompositorContext, &[Cow], PromptEvent) -> anyhow::Result<()>, pub completer: Option, } -fn quit(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn quit(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { log::debug!("quitting..."); if event != PromptEvent::Validate { @@ -42,7 +42,7 @@ fn quit(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> } fn force_quit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -58,7 +58,7 @@ fn force_quit( Ok(()) } -fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn open(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -94,7 +94,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> } fn buffer_close_by_ids_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, doc_ids: &[DocumentId], force: bool, ) -> anyhow::Result<()> { @@ -166,7 +166,7 @@ fn buffer_gather_paths_impl(editor: &mut Editor, args: &[Cow]) -> Vec], event: PromptEvent, ) -> anyhow::Result<()> { @@ -179,7 +179,7 @@ fn buffer_close( } fn force_buffer_close( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -201,7 +201,7 @@ fn buffer_gather_others_impl(editor: &mut Editor) -> Vec { } fn buffer_close_others( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -214,7 +214,7 @@ fn buffer_close_others( } fn force_buffer_close_others( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -231,7 +231,7 @@ fn buffer_gather_all_impl(editor: &mut Editor) -> Vec { } fn buffer_close_all( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -244,7 +244,7 @@ fn buffer_close_all( } fn force_buffer_close_all( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -257,7 +257,7 @@ fn force_buffer_close_all( } fn buffer_next( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -270,7 +270,7 @@ fn buffer_next( } fn buffer_previous( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -283,7 +283,7 @@ fn buffer_previous( } fn write_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, path: Option<&Cow>, force: bool, ) -> anyhow::Result<()> { @@ -317,7 +317,7 @@ fn write_impl( } fn write( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -329,7 +329,7 @@ fn write( } fn force_write( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -341,7 +341,7 @@ fn force_write( } fn new_file( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -355,7 +355,7 @@ fn new_file( } fn format( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -372,7 +372,7 @@ fn format( Ok(()) } fn set_indent_style( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -415,7 +415,7 @@ fn set_indent_style( /// Sets or reports the current document's line ending setting. fn set_line_ending( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -488,7 +488,7 @@ fn set_line_ending( } fn earlier( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -508,7 +508,7 @@ fn earlier( } fn later( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -527,7 +527,7 @@ fn later( } fn write_quit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -541,7 +541,7 @@ fn write_quit( } fn force_write_quit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -580,7 +580,7 @@ pub(super) fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()> } pub fn write_all_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, force: bool, write_scratch: bool, ) -> anyhow::Result<()> { @@ -656,7 +656,7 @@ pub fn write_all_impl( } fn write_all( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -668,7 +668,7 @@ fn write_all( } fn write_all_quit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -680,7 +680,7 @@ fn write_all_quit( } fn force_write_all_quit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -691,7 +691,7 @@ fn force_write_all_quit( quit_all_impl(cx, true) } -fn quit_all_impl(cx: &mut compositor::Context, force: bool) -> anyhow::Result<()> { +fn quit_all_impl(cx: &mut compositor::CompositorContext, force: bool) -> anyhow::Result<()> { cx.block_try_flush_writes()?; if !force { buffers_remaining_impl(cx.editor)?; @@ -707,7 +707,7 @@ fn quit_all_impl(cx: &mut compositor::Context, force: bool) -> anyhow::Result<() } fn quit_all( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -719,7 +719,7 @@ fn quit_all( } fn force_quit_all( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -731,7 +731,7 @@ fn force_quit_all( } fn cquit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -749,7 +749,7 @@ fn cquit( } fn force_cquit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -767,7 +767,7 @@ fn force_cquit( } fn theme( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -812,7 +812,7 @@ fn theme( } fn yank_main_selection_to_clipboard( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -824,7 +824,7 @@ fn yank_main_selection_to_clipboard( } fn yank_joined_to_clipboard( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -839,7 +839,7 @@ fn yank_joined_to_clipboard( } fn yank_main_selection_to_primary_clipboard( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -851,7 +851,7 @@ fn yank_main_selection_to_primary_clipboard( } fn yank_joined_to_primary_clipboard( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -866,7 +866,7 @@ fn yank_joined_to_primary_clipboard( } fn paste_clipboard_after( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -878,7 +878,7 @@ fn paste_clipboard_after( } fn paste_clipboard_before( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -890,7 +890,7 @@ fn paste_clipboard_before( } fn paste_primary_clipboard_after( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -902,7 +902,7 @@ fn paste_primary_clipboard_after( } fn paste_primary_clipboard_before( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -914,7 +914,7 @@ fn paste_primary_clipboard_before( } fn replace_selections_with_clipboard_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, clipboard_type: ClipboardType, ) -> anyhow::Result<()> { let scrolloff = cx.editor.config().scrolloff; @@ -937,7 +937,7 @@ fn replace_selections_with_clipboard_impl( } fn replace_selections_with_clipboard( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -949,7 +949,7 @@ fn replace_selections_with_clipboard( } fn replace_selections_with_primary_clipboard( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -961,7 +961,7 @@ fn replace_selections_with_primary_clipboard( } fn show_clipboard_provider( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -975,7 +975,7 @@ fn show_clipboard_provider( } fn change_current_directory( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1003,7 +1003,7 @@ fn change_current_directory( } fn show_current_directory( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1019,7 +1019,7 @@ fn show_current_directory( /// Sets the [`Document`]'s encoding.. fn set_encoding( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1039,7 +1039,7 @@ fn set_encoding( /// Shows info about the character under the primary cursor. fn get_character_info( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1164,7 +1164,7 @@ fn get_character_info( /// Reload the [`Document`] from its source file. fn reload( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1182,7 +1182,7 @@ fn reload( } fn reload_all( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1233,7 +1233,7 @@ fn reload_all( /// Update the [`Document`] if it has been modified. fn update( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1250,7 +1250,7 @@ fn update( } fn lsp_workspace_command( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1321,7 +1321,7 @@ fn lsp_workspace_command( } fn lsp_restart( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1355,7 +1355,7 @@ fn lsp_restart( } fn tree_sitter_scopes( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1388,7 +1388,7 @@ fn tree_sitter_scopes( } fn vsplit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1411,7 +1411,7 @@ fn vsplit( } fn hsplit( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1434,7 +1434,7 @@ fn hsplit( } fn vsplit_new( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1448,7 +1448,7 @@ fn vsplit_new( } fn hsplit_new( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1462,7 +1462,7 @@ fn hsplit_new( } fn debug_eval( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1488,7 +1488,7 @@ fn debug_eval( } fn debug_start( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1505,7 +1505,7 @@ fn debug_start( } fn debug_remote( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1526,7 +1526,7 @@ fn debug_remote( } fn tutor( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1542,7 +1542,7 @@ fn tutor( } pub(super) fn goto_line_number( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1587,7 +1587,7 @@ pub(super) fn goto_line_number( // Fetch the current value of a config option and output as status. fn get_option( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1613,7 +1613,7 @@ fn get_option( /// Change config at runtime. Access nested values by dot syntax, for /// example to disable smart case search, use `:set search.smart-case false`. fn set_option( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1652,7 +1652,7 @@ fn set_option( /// syntax, for example to toggle smart case search, use `:toggle search.smart- /// case`. fn toggle_option( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1690,7 +1690,7 @@ fn toggle_option( /// Change the language of the current buffer at runtime. fn language( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1723,7 +1723,7 @@ fn language( Ok(()) } -fn sort(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn sort(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -1732,7 +1732,7 @@ fn sort(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> } fn sort_reverse( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1744,7 +1744,7 @@ fn sort_reverse( } fn sort_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], reverse: bool, ) -> anyhow::Result<()> { @@ -1780,7 +1780,7 @@ fn sort_impl( } fn reflow( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1825,7 +1825,7 @@ fn reflow( } fn tree_sitter_subtree( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1868,7 +1868,7 @@ fn tree_sitter_subtree( } fn open_config( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1882,7 +1882,7 @@ fn open_config( } fn open_log( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1895,7 +1895,7 @@ fn open_log( } fn refresh_config( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1908,7 +1908,7 @@ fn refresh_config( } fn append_output( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1922,7 +1922,7 @@ fn append_output( } fn insert_output( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1936,19 +1936,19 @@ fn insert_output( } fn pipe_to( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { pipe_impl(cx, args, event, &ShellBehavior::Ignore) } -fn pipe(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn pipe(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { pipe_impl(cx, args, event, &ShellBehavior::Replace) } fn pipe_impl( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, behavior: &ShellBehavior, @@ -1963,7 +1963,7 @@ fn pipe_impl( } fn run_shell_command( - cx: &mut compositor::Context, + cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -2607,7 +2607,7 @@ pub(super) fn command_mode(cx: &mut Context) { } } }, // completion - move |cx: &mut compositor::Context, input: &str, event: PromptEvent| { + move |cx: &mut compositor::CompositorContext, input: &str, event: PromptEvent| { let parts = input.split_whitespace().collect::>(); if parts.is_empty() { return; diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index bcb3e44904e4..1451fbb94ee7 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -6,8 +6,8 @@ use helix_view::graphics::{CursorKind, Rect}; use tui::buffer::Buffer as Surface; -pub type Callback = Box; -pub type SyncCallback = Box; +pub type Callback = Box; +pub type SyncCallback = Box; // Cursive-inspired pub enum EventResult { @@ -20,13 +20,13 @@ use helix_view::Editor; pub use helix_view::input::Event; -pub struct Context<'a> { +pub struct CompositorContext<'a> { pub editor: &'a mut Editor, pub scroll: Option, pub jobs: &'a mut Jobs, } -impl<'a> Context<'a> { +impl<'a> CompositorContext<'a> { /// Waits on all pending jobs, and then tries to flush all pending write /// operations for all documents. pub fn block_try_flush_writes(&mut self) -> anyhow::Result<()> { @@ -38,7 +38,7 @@ impl<'a> Context<'a> { pub trait Component: Any + AnyComponent { /// Process input events, return true if handled. - fn handle_event(&mut self, _event: &Event, _ctx: &mut Context) -> EventResult { + fn handle_event(&mut self, _event: &Event, _ctx: &mut CompositorContext) -> EventResult { EventResult::Ignored(None) } // , args: () @@ -49,7 +49,7 @@ pub trait Component: Any + AnyComponent { } /// Render the component onto the provided surface. - fn render(&mut self, area: Rect, frame: &mut Surface, ctx: &mut Context); + fn render(&mut self, area: Rect, frame: &mut Surface, ctx: &mut CompositorContext); /// Get cursor position and cursor kind. fn cursor(&self, _area: Rect, _ctx: &Editor) -> (Option, CursorKind) { @@ -128,7 +128,7 @@ impl Compositor { Some(self.layers.remove(idx)) } - pub fn handle_event(&mut self, event: &Event, cx: &mut Context) -> bool { + pub fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> bool { // If it is a key event and a macro is being recorded, push the key event to the recording. if let (Event::Key(key), Some((_, keys))) = (event, &mut cx.editor.macro_recording) { keys.push(*key); @@ -165,7 +165,7 @@ impl Compositor { consumed } - pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { for layer in &mut self.layers { layer.render(area, surface, cx); } diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index a24da20a9fac..95c1bcdab04c 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,4 +1,4 @@ -use crate::compositor::{Component, Context, Event, EventResult}; +use crate::compositor::{Component, CompositorContext, Event, EventResult}; use helix_view::{ editor::CompleteAction, theme::{Modifier, Style}, @@ -375,7 +375,7 @@ impl Completion { } impl Component for Completion { - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { self.popup.handle_event(event, cx) } @@ -383,7 +383,7 @@ impl Component for Completion { self.popup.required_size(viewport) } - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { self.popup.render(area, surface, cx); // if we have a selection, render a markdown popup on top/below with info diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 59f371bda5dc..027e001cff55 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1,6 +1,6 @@ use crate::{ commands::{self, OnKeyCallback}, - compositor::{Component, Context, Event, EventResult}, + compositor::{Component, CompositorContext, Event, EventResult}, job::{self, Callback}, key, keymap::{KeymapResult, Keymaps}, @@ -1185,7 +1185,7 @@ impl Component for EditorView { fn handle_event( &mut self, event: &Event, - context: &mut crate::compositor::Context, + context: &mut crate::compositor::CompositorContext, ) -> EventResult { let mut cx = commands::Context { editor: context.editor, @@ -1241,7 +1241,7 @@ impl Component for EditorView { let mut consumed = false; if let Some(completion) = &mut self.completion { // use a fake context here - let mut cx = Context { + let mut cx = CompositorContext { editor: cx.editor, jobs: cx.jobs, scroll: None, @@ -1330,7 +1330,7 @@ impl Component for EditorView { } } - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { // clear with background color surface.set_style(area, cx.editor.theme.get("ui.background")); let config = cx.editor.config(); diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs index cc6b7483f887..7eb41b63732b 100644 --- a/helix-term/src/ui/info.rs +++ b/helix-term/src/ui/info.rs @@ -1,11 +1,11 @@ -use crate::compositor::{Component, Context}; +use crate::compositor::{Component, CompositorContext}; use helix_view::graphics::{Margin, Rect}; use helix_view::info::Info; use tui::buffer::Buffer as Surface; use tui::widgets::{Block, Borders, Paragraph, Widget}; impl Component for Info { - fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut CompositorContext) { let text_style = cx.editor.theme.get("ui.text.info"); let popup_style = cx.editor.theme.get("ui.popup.info"); diff --git a/helix-term/src/ui/lsp.rs b/helix-term/src/ui/lsp.rs index 44050aa12969..8baab1a5a714 100644 --- a/helix-term/src/ui/lsp.rs +++ b/helix-term/src/ui/lsp.rs @@ -5,7 +5,7 @@ use helix_view::graphics::{Margin, Rect, Style}; use tui::buffer::Buffer; use tui::widgets::{BorderType, Paragraph, Widget, Wrap}; -use crate::compositor::{Component, Compositor, Context}; +use crate::compositor::{Component, Compositor, CompositorContext}; use crate::ui::Markdown; @@ -48,7 +48,7 @@ impl SignatureHelp { } impl Component for SignatureHelp { - fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Buffer, cx: &mut CompositorContext) { let margin = Margin::horizontal(1); let active_param_span = self.active_param_range.map(|(start, end)| { diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 923dd73a16ab..e31519659123 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -1,4 +1,4 @@ -use crate::compositor::{Component, Context}; +use crate::compositor::{Component, CompositorContext}; use tui::{ buffer::Buffer as Surface, text::{Span, Spans, Text}, @@ -327,7 +327,7 @@ impl Markdown { } impl Component for Markdown { - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { use tui::widgets::{Paragraph, Widget, Wrap}; let text = self.parse(Some(&cx.editor.theme)); diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 30625acee60c..9afed769d955 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, path::PathBuf}; use crate::{ - compositor::{Callback, Component, Compositor, Context, Event, EventResult}, + compositor::{Callback, Component, Compositor, CompositorContext, Event, EventResult}, ctrl, key, shift, }; use tui::{buffer::Buffer as Surface, widgets::Table}; @@ -236,7 +236,7 @@ impl Menu { use super::PromptEvent as MenuEvent; impl Component for Menu { - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { let event = match event { Event::Key(event) => *event, _ => return EventResult::Ignored(None), @@ -302,7 +302,7 @@ impl Component for Menu { Some(self.size) } - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { let theme = &cx.editor.theme; let style = theme .try_get("ui.menu") diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index d7717f8cf59c..e77e09118c74 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -38,7 +38,7 @@ pub fn prompt( prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, - callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static, + callback_fn: impl FnMut(&mut crate::compositor::CompositorContext, &str, PromptEvent) + 'static, ) { let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn); // Calculate the initial completion @@ -52,7 +52,7 @@ pub fn prompt_with_input( input: String, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, - callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static, + callback_fn: impl FnMut(&mut crate::compositor::CompositorContext, &str, PromptEvent) + 'static, ) { let prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn) .with_line(input, cx.editor); @@ -76,7 +76,7 @@ pub fn regex_prompt( prompt, history_register, completion_fn, - move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| { + move |cx: &mut crate::compositor::CompositorContext, input: &str, event: PromptEvent| { match event { PromptEvent::Abort => { let (view, doc) = current!(cx.editor); diff --git a/helix-term/src/ui/overlay.rs b/helix-term/src/ui/overlay.rs index 5b2bc806093d..06f06f18f80c 100644 --- a/helix-term/src/ui/overlay.rs +++ b/helix-term/src/ui/overlay.rs @@ -5,7 +5,7 @@ use helix_view::{ }; use tui::buffer::Buffer; -use crate::compositor::{Component, Context, Event, EventResult}; +use crate::compositor::{Component, CompositorContext, Event, EventResult}; /// Contains a component placed in the center of the parent component pub struct Overlay { @@ -43,7 +43,7 @@ fn clip_rect_relative(rect: Rect, percent_horizontal: u8, percent_vertical: u8) } impl Component for Overlay { - fn render(&mut self, area: Rect, frame: &mut Buffer, ctx: &mut Context) { + fn render(&mut self, area: Rect, frame: &mut Buffer, ctx: &mut CompositorContext) { let dimensions = (self.calc_child_size)(area); self.content.render(dimensions, frame, ctx) } @@ -61,7 +61,7 @@ impl Component for Overlay { Some((width, height)) } - fn handle_event(&mut self, event: &Event, ctx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, ctx: &mut CompositorContext) -> EventResult { self.content.handle_event(event, ctx) } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 803e2d65bb78..0c5fac28a1ab 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -1,6 +1,6 @@ use crate::{ alt, - compositor::{Component, Compositor, Context, Event, EventResult}, + compositor::{Component, Compositor, CompositorContext, Event, EventResult}, ctrl, key, shift, ui::{ self, @@ -126,7 +126,7 @@ impl FilePicker { pub fn new( options: Vec, editor_data: T::Data, - callback_fn: impl Fn(&mut Context, &T, Action) + 'static, + callback_fn: impl Fn(&mut CompositorContext, &T, Action) + 'static, preview_fn: impl Fn(&Editor, &T) -> Option + 'static, ) -> Self { let truncate_start = true; @@ -207,7 +207,7 @@ impl FilePicker { } } - fn handle_idle_timeout(&mut self, cx: &mut Context) -> EventResult { + fn handle_idle_timeout(&mut self, cx: &mut CompositorContext) -> EventResult { // Try to find a document in the cache let doc = self .current_file(cx.editor) @@ -232,7 +232,7 @@ impl FilePicker { } impl Component for FilePicker { - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { // +---------+ +---------+ // |prompt | |preview | // +---------+ | | @@ -348,7 +348,7 @@ impl Component for FilePicker { } } - fn handle_event(&mut self, event: &Event, ctx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, ctx: &mut CompositorContext) -> EventResult { if let Event::IdleTimeout = event { return self.handle_idle_timeout(ctx); } @@ -396,7 +396,7 @@ impl Ord for PickerMatch { } } -type PickerCallback = Box; +type PickerCallback = Box; pub struct Picker { options: Vec, @@ -426,13 +426,13 @@ impl Picker { pub fn new( options: Vec, editor_data: T::Data, - callback_fn: impl Fn(&mut Context, &T, Action) + 'static, + callback_fn: impl Fn(&mut CompositorContext, &T, Action) + 'static, ) -> Self { let prompt = Prompt::new( "".into(), None, ui::completers::none, - |_editor: &mut Context, _pattern: &str, _event: PromptEvent| {}, + |_editor: &mut CompositorContext, _pattern: &str, _event: PromptEvent| {}, ); let n = options @@ -613,7 +613,7 @@ impl Picker { self.show_preview = !self.show_preview; } - fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn prompt_handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) { // TODO: recalculate only if pattern changed self.score(); @@ -633,7 +633,7 @@ impl Component for Picker { Some(viewport) } - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { let key_event = match event { Event::Key(event) => *event, Event::Paste(..) => return self.prompt_handle_event(event, cx), @@ -705,7 +705,7 @@ impl Component for Picker { EventResult::Consumed(None) } - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { let text_style = cx.editor.theme.get("ui.text"); let selected = cx.editor.theme.get("ui.text.focus"); let highlight_style = cx.editor.theme.get("special").add_modifier(Modifier::BOLD); @@ -905,11 +905,11 @@ impl DynamicPicker { } impl Component for DynamicPicker { - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { self.file_picker.render(area, surface, cx); } - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { let event_result = self.file_picker.handle_event(event, cx); let current_query = self.file_picker.picker.prompt.line(); diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 5a95c1bbae79..62985a698182 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -1,6 +1,6 @@ use crate::{ commands::Open, - compositor::{Callback, Component, Context, Event, EventResult}, + compositor::{Callback, Component, CompositorContext, Event, EventResult}, ctrl, key, }; use tui::buffer::Buffer as Surface; @@ -88,7 +88,7 @@ impl Popup { /// Calculate the position where the popup should be rendered and return the coordinates of the /// top left corner. - pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) { + pub fn get_rel_position(&mut self, viewport: Rect, cx: &CompositorContext) -> (u16, u16) { let position = self .position .get_or_insert_with(|| cx.editor.cursor().0.unwrap_or_default()); @@ -158,7 +158,7 @@ impl Popup { } impl Component for Popup { - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { let key = match event { Event::Key(event) => *event, Event::Resize(_, _) => { @@ -231,7 +231,7 @@ impl Component for Popup { Some(self.size) } - fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut CompositorContext) { // trigger required_size so we recalculate if the child changed self.required_size((viewport.width, viewport.height)); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index f438231fa9c0..2c79a4a0f577 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -1,4 +1,4 @@ -use crate::compositor::{Component, Compositor, Context, Event, EventResult}; +use crate::compositor::{Component, Compositor, CompositorContext, Event, EventResult}; use crate::{alt, ctrl, key, shift, ui}; use helix_view::input::KeyEvent; use helix_view::keyboard::KeyCode; @@ -14,10 +14,10 @@ use helix_view::{ Editor, }; -type PromptCharHandler = Box; +type PromptCharHandler = Box; pub type Completion = (RangeFrom, Cow<'static, str>); type CompletionFn = Box Vec>; -type CallbackFn = Box; +type CallbackFn = Box; pub type DocFn = Box Option>>; pub struct Prompt { @@ -69,7 +69,7 @@ impl Prompt { prompt: Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, - callback_fn: impl FnMut(&mut Context, &str, PromptEvent) + 'static, + callback_fn: impl FnMut(&mut CompositorContext, &str, PromptEvent) + 'static, ) -> Self { Self { prompt, @@ -204,7 +204,7 @@ impl Prompt { } } - pub fn insert_char(&mut self, c: char, cx: &Context) { + pub fn insert_char(&mut self, c: char, cx: &CompositorContext) { if let Some(handler) = &self.next_char_handler.take() { handler(self, c, cx); @@ -292,7 +292,7 @@ impl Prompt { pub fn change_history( &mut self, - cx: &mut Context, + cx: &mut CompositorContext, register: char, direction: CompletionDirection, ) { @@ -350,7 +350,7 @@ impl Prompt { const BASE_WIDTH: u16 = 30; impl Prompt { - pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut Context) { + pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { let theme = &cx.editor.theme; let prompt_color = theme.get("ui.text"); let completion_color = theme.get("ui.menu"); @@ -482,7 +482,7 @@ impl Prompt { } impl Component for Prompt { - fn handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult { + fn handle_event(&mut self, event: &Event, cx: &mut CompositorContext) -> EventResult { let event = match event { Event::Paste(data) => { self.insert_str(data, cx.editor); @@ -637,7 +637,7 @@ impl Component for Prompt { EventResult::Consumed(None) } - fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut CompositorContext) { self.render_prompt(area, surface, cx) } diff --git a/helix-term/src/ui/text.rs b/helix-term/src/ui/text.rs index c318052b2dd0..a00f198c7824 100644 --- a/helix-term/src/ui/text.rs +++ b/helix-term/src/ui/text.rs @@ -1,4 +1,4 @@ -use crate::compositor::{Component, Context}; +use crate::compositor::{Component, CompositorContext}; use tui::buffer::Buffer as Surface; use helix_view::graphics::Rect; @@ -30,7 +30,7 @@ impl From> for Text { } impl Component for Text { - fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) { + fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut CompositorContext) { use tui::widgets::{Paragraph, Widget, Wrap}; let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false }); From 3b36de15589dd3648160ab0ea0b22af842df6fe7 Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sun, 19 Feb 2023 20:45:00 +0100 Subject: [PATCH 2/5] (renaming) Context -> CommandContext --- helix-term/src/commands.rs | 538 +++++++++++++++---------------- helix-term/src/commands/dap.rs | 36 +-- helix-term/src/commands/lsp.rs | 34 +- helix-term/src/commands/typed.rs | 2 +- helix-term/src/ui/completion.rs | 4 +- helix-term/src/ui/editor.rs | 12 +- helix-term/src/ui/mod.rs | 6 +- 7 files changed, 316 insertions(+), 316 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index f3c0f833c07c..a6fc62b01e72 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -73,9 +73,9 @@ use grep_searcher::{sinks, BinaryDetection, SearcherBuilder}; use ignore::{DirEntry, WalkBuilder, WalkState}; use tokio_stream::wrappers::UnboundedReceiverStream; -pub type OnKeyCallback = Box; +pub type OnKeyCallback = Box; -pub struct Context<'a> { +pub struct CommandContext<'a> { pub register: Option, pub count: Option, pub editor: &'a mut Editor, @@ -85,7 +85,7 @@ pub struct Context<'a> { pub jobs: &'a mut Jobs, } -impl<'a> Context<'a> { +impl<'a> CommandContext<'a> { /// Push a new component onto the compositor. pub fn push_layer(&mut self, component: Box) { self.callback = Some(Box::new(|compositor: &mut Compositor, _| { @@ -96,7 +96,7 @@ impl<'a> Context<'a> { #[inline] pub fn on_next_key( &mut self, - on_next_key_callback: impl FnOnce(&mut Context, KeyEvent) + 'static, + on_next_key_callback: impl FnOnce(&mut CommandContext, KeyEvent) + 'static, ) { self.on_next_key_callback = Some(Box::new(on_next_key_callback)); } @@ -144,7 +144,7 @@ pub enum MappableCommand { }, Static { name: &'static str, - fun: fn(cx: &mut Context), + fun: fn(cx: &mut CommandContext), doc: &'static str, }, } @@ -167,7 +167,7 @@ macro_rules! static_commands { } impl MappableCommand { - pub fn execute(&self, cx: &mut Context) { + pub fn execute(&self, cx: &mut CommandContext) { match &self { Self::Typable { name, args, doc: _ } => { let args: Vec> = args.iter().map(Cow::from).collect(); @@ -548,12 +548,12 @@ impl PartialEq for MappableCommand { } } -fn no_op(_cx: &mut Context) {} +fn no_op(_cx: &mut CommandContext) {} type MoveFn = fn(RopeSlice, Range, Direction, usize, Movement, &TextFormat, &mut TextAnnotations) -> Range; -fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movement) { +fn move_impl(cx: &mut CommandContext, move_fn: MoveFn, dir: Direction, behaviour: Movement) { let count = cx.count(); let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -576,23 +576,23 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem use helix_core::movement::{move_horizontally, move_vertically}; -fn move_char_left(cx: &mut Context) { +fn move_char_left(cx: &mut CommandContext) { move_impl(cx, move_horizontally, Direction::Backward, Movement::Move) } -fn move_char_right(cx: &mut Context) { +fn move_char_right(cx: &mut CommandContext) { move_impl(cx, move_horizontally, Direction::Forward, Movement::Move) } -fn move_line_up(cx: &mut Context) { +fn move_line_up(cx: &mut CommandContext) { move_impl(cx, move_vertically, Direction::Backward, Movement::Move) } -fn move_line_down(cx: &mut Context) { +fn move_line_down(cx: &mut CommandContext) { move_impl(cx, move_vertically, Direction::Forward, Movement::Move) } -fn move_visual_line_up(cx: &mut Context) { +fn move_visual_line_up(cx: &mut CommandContext) { move_impl( cx, move_vertically_visual, @@ -601,7 +601,7 @@ fn move_visual_line_up(cx: &mut Context) { ) } -fn move_visual_line_down(cx: &mut Context) { +fn move_visual_line_down(cx: &mut CommandContext) { move_impl( cx, move_vertically_visual, @@ -610,23 +610,23 @@ fn move_visual_line_down(cx: &mut Context) { ) } -fn extend_char_left(cx: &mut Context) { +fn extend_char_left(cx: &mut CommandContext) { move_impl(cx, move_horizontally, Direction::Backward, Movement::Extend) } -fn extend_char_right(cx: &mut Context) { +fn extend_char_right(cx: &mut CommandContext) { move_impl(cx, move_horizontally, Direction::Forward, Movement::Extend) } -fn extend_line_up(cx: &mut Context) { +fn extend_line_up(cx: &mut CommandContext) { move_impl(cx, move_vertically, Direction::Backward, Movement::Extend) } -fn extend_line_down(cx: &mut Context) { +fn extend_line_down(cx: &mut CommandContext) { move_impl(cx, move_vertically, Direction::Forward, Movement::Extend) } -fn extend_visual_line_up(cx: &mut Context) { +fn extend_visual_line_up(cx: &mut CommandContext) { move_impl( cx, move_vertically_visual, @@ -635,7 +635,7 @@ fn extend_visual_line_up(cx: &mut Context) { ) } -fn extend_visual_line_down(cx: &mut Context) { +fn extend_visual_line_down(cx: &mut CommandContext) { move_impl( cx, move_vertically_visual, @@ -659,7 +659,7 @@ fn goto_line_end_impl(view: &mut View, doc: &mut Document, movement: Movement) { doc.set_selection(view.id, selection); } -fn goto_line_end(cx: &mut Context) { +fn goto_line_end(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); goto_line_end_impl( view, @@ -672,7 +672,7 @@ fn goto_line_end(cx: &mut Context) { ) } -fn extend_to_line_end(cx: &mut Context) { +fn extend_to_line_end(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); goto_line_end_impl(view, doc, Movement::Extend) } @@ -689,7 +689,7 @@ fn goto_line_end_newline_impl(view: &mut View, doc: &mut Document, movement: Mov doc.set_selection(view.id, selection); } -fn goto_line_end_newline(cx: &mut Context) { +fn goto_line_end_newline(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); goto_line_end_newline_impl( view, @@ -702,7 +702,7 @@ fn goto_line_end_newline(cx: &mut Context) { ) } -fn extend_to_line_end_newline(cx: &mut Context) { +fn extend_to_line_end_newline(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); goto_line_end_newline_impl(view, doc, Movement::Extend) } @@ -720,7 +720,7 @@ fn goto_line_start_impl(view: &mut View, doc: &mut Document, movement: Movement) doc.set_selection(view.id, selection); } -fn goto_line_start(cx: &mut Context) { +fn goto_line_start(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); goto_line_start_impl( view, @@ -733,11 +733,11 @@ fn goto_line_start(cx: &mut Context) { ) } -fn goto_next_buffer(cx: &mut Context) { +fn goto_next_buffer(cx: &mut CommandContext) { goto_buffer(cx.editor, Direction::Forward); } -fn goto_previous_buffer(cx: &mut Context) { +fn goto_previous_buffer(cx: &mut CommandContext) { goto_buffer(cx.editor, Direction::Backward); } @@ -765,12 +765,12 @@ fn goto_buffer(editor: &mut Editor, direction: Direction) { editor.switch(id, Action::Replace); } -fn extend_to_line_start(cx: &mut Context) { +fn extend_to_line_start(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); goto_line_start_impl(view, doc, Movement::Extend) } -fn kill_to_line_start(cx: &mut Context) { +fn kill_to_line_start(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -800,7 +800,7 @@ fn kill_to_line_start(cx: &mut Context) { lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic); } -fn kill_to_line_end(cx: &mut Context) { +fn kill_to_line_end(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -821,7 +821,7 @@ fn kill_to_line_end(cx: &mut Context) { lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic); } -fn goto_first_nonwhitespace(cx: &mut Context) { +fn goto_first_nonwhitespace(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -838,7 +838,7 @@ fn goto_first_nonwhitespace(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn trim_selections(cx: &mut Context) { +fn trim_selections(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -872,7 +872,7 @@ fn trim_selections(cx: &mut Context) { // align text in selection #[allow(deprecated)] -fn align_selections(cx: &mut Context) { +fn align_selections(cx: &mut CommandContext) { use helix_core::visual_coords_at_pos; let (view, doc) = current!(cx.editor); @@ -938,7 +938,7 @@ fn align_selections(cx: &mut Context) { doc.apply(&transaction, view.id); } -fn goto_window(cx: &mut Context, align: Align) { +fn goto_window(cx: &mut CommandContext, align: Align) { let count = cx.count() - 1; let config = cx.editor.config(); let (view, doc) = current!(cx.editor); @@ -976,19 +976,19 @@ fn goto_window(cx: &mut Context, align: Align) { doc.set_selection(view.id, selection); } -fn goto_window_top(cx: &mut Context) { +fn goto_window_top(cx: &mut CommandContext) { goto_window(cx, Align::Top) } -fn goto_window_center(cx: &mut Context) { +fn goto_window_center(cx: &mut CommandContext) { goto_window(cx, Align::Center) } -fn goto_window_bottom(cx: &mut Context) { +fn goto_window_bottom(cx: &mut CommandContext) { goto_window(cx, Align::Bottom) } -fn move_word_impl(cx: &mut Context, move_fn: F) +fn move_word_impl(cx: &mut CommandContext, move_fn: F) where F: Fn(RopeSlice, Range, usize) -> Range, { @@ -1003,35 +1003,35 @@ where doc.set_selection(view.id, selection); } -fn move_next_word_start(cx: &mut Context) { +fn move_next_word_start(cx: &mut CommandContext) { move_word_impl(cx, movement::move_next_word_start) } -fn move_prev_word_start(cx: &mut Context) { +fn move_prev_word_start(cx: &mut CommandContext) { move_word_impl(cx, movement::move_prev_word_start) } -fn move_prev_word_end(cx: &mut Context) { +fn move_prev_word_end(cx: &mut CommandContext) { move_word_impl(cx, movement::move_prev_word_end) } -fn move_next_word_end(cx: &mut Context) { +fn move_next_word_end(cx: &mut CommandContext) { move_word_impl(cx, movement::move_next_word_end) } -fn move_next_long_word_start(cx: &mut Context) { +fn move_next_long_word_start(cx: &mut CommandContext) { move_word_impl(cx, movement::move_next_long_word_start) } -fn move_prev_long_word_start(cx: &mut Context) { +fn move_prev_long_word_start(cx: &mut CommandContext) { move_word_impl(cx, movement::move_prev_long_word_start) } -fn move_next_long_word_end(cx: &mut Context) { +fn move_next_long_word_end(cx: &mut CommandContext) { move_word_impl(cx, movement::move_next_long_word_end) } -fn goto_para_impl(cx: &mut Context, move_fn: F) +fn goto_para_impl(cx: &mut CommandContext, move_fn: F) where F: Fn(RopeSlice, Range, usize, Movement) -> Range + 'static, { @@ -1055,15 +1055,15 @@ where cx.editor.last_motion = Some(Motion(Box::new(motion))); } -fn goto_prev_paragraph(cx: &mut Context) { +fn goto_prev_paragraph(cx: &mut CommandContext) { goto_para_impl(cx, movement::move_prev_paragraph) } -fn goto_next_paragraph(cx: &mut Context) { +fn goto_next_paragraph(cx: &mut CommandContext) { goto_para_impl(cx, movement::move_next_paragraph) } -fn goto_file_start(cx: &mut Context) { +fn goto_file_start(cx: &mut CommandContext) { if cx.count.is_some() { goto_line(cx); } else { @@ -1078,7 +1078,7 @@ fn goto_file_start(cx: &mut Context) { } } -fn goto_file_end(cx: &mut Context) { +fn goto_file_end(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); let pos = doc.text().len_chars(); @@ -1090,20 +1090,20 @@ fn goto_file_end(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn goto_file(cx: &mut Context) { +fn goto_file(cx: &mut CommandContext) { goto_file_impl(cx, Action::Replace); } -fn goto_file_hsplit(cx: &mut Context) { +fn goto_file_hsplit(cx: &mut CommandContext) { goto_file_impl(cx, Action::HorizontalSplit); } -fn goto_file_vsplit(cx: &mut Context) { +fn goto_file_vsplit(cx: &mut CommandContext) { goto_file_impl(cx, Action::VerticalSplit); } /// Goto files in selection. -fn goto_file_impl(cx: &mut Context, action: Action) { +fn goto_file_impl(cx: &mut CommandContext, action: Action) { let (view, doc) = current_ref!(cx.editor); let text = doc.text(); let selections = doc.selection(view.id); @@ -1144,7 +1144,7 @@ fn goto_file_impl(cx: &mut Context, action: Action) { } } -fn extend_word_impl(cx: &mut Context, extend_fn: F) +fn extend_word_impl(cx: &mut CommandContext, extend_fn: F) where F: Fn(RopeSlice, Range, usize) -> Range, { @@ -1160,35 +1160,35 @@ where doc.set_selection(view.id, selection); } -fn extend_next_word_start(cx: &mut Context) { +fn extend_next_word_start(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_next_word_start) } -fn extend_prev_word_start(cx: &mut Context) { +fn extend_prev_word_start(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_prev_word_start) } -fn extend_next_word_end(cx: &mut Context) { +fn extend_next_word_end(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_next_word_end) } -fn extend_prev_word_end(cx: &mut Context) { +fn extend_prev_word_end(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_prev_word_end) } -fn extend_next_long_word_start(cx: &mut Context) { +fn extend_next_long_word_start(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_next_long_word_start) } -fn extend_prev_long_word_start(cx: &mut Context) { +fn extend_prev_long_word_start(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_prev_long_word_start) } -fn extend_next_long_word_end(cx: &mut Context) { +fn extend_next_long_word_end(cx: &mut CommandContext) { extend_word_impl(cx, movement::move_next_long_word_end) } -fn will_find_char(cx: &mut Context, search_fn: F, inclusive: bool, extend: bool) +fn will_find_char(cx: &mut CommandContext, search_fn: F, inclusive: bool, extend: bool) where F: Fn(RopeSlice, char, usize, usize, bool) -> Option + 'static, { @@ -1305,39 +1305,39 @@ fn find_prev_char_impl( } } -fn find_till_char(cx: &mut Context) { +fn find_till_char(cx: &mut CommandContext) { will_find_char(cx, find_next_char_impl, false, false) } -fn find_next_char(cx: &mut Context) { +fn find_next_char(cx: &mut CommandContext) { will_find_char(cx, find_next_char_impl, true, false) } -fn extend_till_char(cx: &mut Context) { +fn extend_till_char(cx: &mut CommandContext) { will_find_char(cx, find_next_char_impl, false, true) } -fn extend_next_char(cx: &mut Context) { +fn extend_next_char(cx: &mut CommandContext) { will_find_char(cx, find_next_char_impl, true, true) } -fn till_prev_char(cx: &mut Context) { +fn till_prev_char(cx: &mut CommandContext) { will_find_char(cx, find_prev_char_impl, false, false) } -fn find_prev_char(cx: &mut Context) { +fn find_prev_char(cx: &mut CommandContext) { will_find_char(cx, find_prev_char_impl, true, false) } -fn extend_till_prev_char(cx: &mut Context) { +fn extend_till_prev_char(cx: &mut CommandContext) { will_find_char(cx, find_prev_char_impl, false, true) } -fn extend_prev_char(cx: &mut Context) { +fn extend_prev_char(cx: &mut CommandContext) { will_find_char(cx, find_prev_char_impl, true, true) } -fn repeat_last_motion(cx: &mut Context) { +fn repeat_last_motion(cx: &mut CommandContext) { let count = cx.count(); let last_motion = cx.editor.last_motion.take(); if let Some(m) = &last_motion { @@ -1348,7 +1348,7 @@ fn repeat_last_motion(cx: &mut Context) { } } -fn replace(cx: &mut Context) { +fn replace(cx: &mut CommandContext) { let mut buf = [0u8; 4]; // To hold utf8 encoded char. // need to wait for next key @@ -1399,7 +1399,7 @@ fn replace(cx: &mut Context) { }) } -fn switch_case_impl(cx: &mut Context, change_fn: F) +fn switch_case_impl(cx: &mut CommandContext, change_fn: F) where F: Fn(RopeSlice) -> Tendril, { @@ -1414,7 +1414,7 @@ where doc.apply(&transaction, view.id); } -fn switch_case(cx: &mut Context) { +fn switch_case(cx: &mut CommandContext) { switch_case_impl(cx, |string| { string .chars() @@ -1431,19 +1431,19 @@ fn switch_case(cx: &mut Context) { }); } -fn switch_to_uppercase(cx: &mut Context) { +fn switch_to_uppercase(cx: &mut CommandContext) { switch_case_impl(cx, |string| { string.chunks().map(|chunk| chunk.to_uppercase()).collect() }); } -fn switch_to_lowercase(cx: &mut Context) { +fn switch_to_lowercase(cx: &mut CommandContext) { switch_case_impl(cx, |string| { string.chunks().map(|chunk| chunk.to_lowercase()).collect() }); } -pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { +pub fn scroll(cx: &mut CommandContext, offset: usize, direction: Direction) { use Direction::*; let config = cx.editor.config(); let (view, doc) = current!(cx.editor); @@ -1519,25 +1519,25 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { doc.set_selection(view.id, sel); } -fn page_up(cx: &mut Context) { +fn page_up(cx: &mut CommandContext) { let view = view!(cx.editor); let offset = view.inner_height(); scroll(cx, offset, Direction::Backward); } -fn page_down(cx: &mut Context) { +fn page_down(cx: &mut CommandContext) { let view = view!(cx.editor); let offset = view.inner_height(); scroll(cx, offset, Direction::Forward); } -fn half_page_up(cx: &mut Context) { +fn half_page_up(cx: &mut CommandContext) { let view = view!(cx.editor); let offset = view.inner_height() / 2; scroll(cx, offset, Direction::Backward); } -fn half_page_down(cx: &mut Context) { +fn half_page_down(cx: &mut CommandContext) { let view = view!(cx.editor); let offset = view.inner_height() / 2; scroll(cx, offset, Direction::Forward); @@ -1549,7 +1549,7 @@ fn half_page_down(cx: &mut Context) { // about "text visual position" // // TODO: implement a variant of that uses visual lines and respects virtual text -fn copy_selection_on_line(cx: &mut Context, direction: Direction) { +fn copy_selection_on_line(cx: &mut CommandContext, direction: Direction) { use helix_core::{pos_at_visual_coords, visual_coords_at_pos}; let count = cx.count(); @@ -1630,22 +1630,22 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) { doc.set_selection(view.id, selection); } -fn copy_selection_on_prev_line(cx: &mut Context) { +fn copy_selection_on_prev_line(cx: &mut CommandContext) { copy_selection_on_line(cx, Direction::Backward) } -fn copy_selection_on_next_line(cx: &mut Context) { +fn copy_selection_on_next_line(cx: &mut CommandContext) { copy_selection_on_line(cx, Direction::Forward) } -fn select_all(cx: &mut Context) { +fn select_all(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let end = doc.text().len_chars(); doc.set_selection(view.id, Selection::single(0, end)) } -fn select_regex(cx: &mut Context) { +fn select_regex(cx: &mut CommandContext) { let reg = cx.register.unwrap_or('/'); ui::regex_prompt( cx, @@ -1667,7 +1667,7 @@ fn select_regex(cx: &mut Context) { ); } -fn split_selection(cx: &mut Context) { +fn split_selection(cx: &mut CommandContext) { let reg = cx.register.unwrap_or('/'); ui::regex_prompt( cx, @@ -1686,7 +1686,7 @@ fn split_selection(cx: &mut Context) { ); } -fn split_selection_on_newline(cx: &mut Context) { +fn split_selection_on_newline(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); // only compile the regex once @@ -1697,7 +1697,7 @@ fn split_selection_on_newline(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn merge_consecutive_selections(cx: &mut Context) { +fn merge_consecutive_selections(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let selection = doc.selection(view.id).clone().merge_consecutive_ranges(); doc.set_selection(view.id, selection); @@ -1790,7 +1790,7 @@ fn search_impl( }; } -fn search_completions(cx: &mut Context, reg: Option) -> Vec { +fn search_completions(cx: &mut CommandContext, reg: Option) -> Vec { let mut items = reg .and_then(|reg| cx.editor.registers.get(reg)) .map_or(Vec::new(), |reg| reg.read().iter().take(200).collect()); @@ -1799,15 +1799,15 @@ fn search_completions(cx: &mut Context, reg: Option) -> Vec { items.into_iter().cloned().collect() } -fn search(cx: &mut Context) { +fn search(cx: &mut CommandContext) { searcher(cx, Direction::Forward) } -fn rsearch(cx: &mut Context) { +fn rsearch(cx: &mut CommandContext) { searcher(cx, Direction::Backward) } -fn searcher(cx: &mut Context, direction: Direction) { +fn searcher(cx: &mut CommandContext, direction: Direction) { let reg = cx.register.unwrap_or('/'); let config = cx.editor.config(); let scrolloff = config.scrolloff; @@ -1851,7 +1851,7 @@ fn searcher(cx: &mut Context, direction: Direction) { ); } -fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) { +fn search_next_or_prev_impl(cx: &mut CommandContext, movement: Movement, direction: Direction) { let count = cx.count(); let config = cx.editor.config(); let scrolloff = config.scrolloff; @@ -1890,22 +1890,22 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir } } -fn search_next(cx: &mut Context) { +fn search_next(cx: &mut CommandContext) { search_next_or_prev_impl(cx, Movement::Move, Direction::Forward); } -fn search_prev(cx: &mut Context) { +fn search_prev(cx: &mut CommandContext) { search_next_or_prev_impl(cx, Movement::Move, Direction::Backward); } -fn extend_search_next(cx: &mut Context) { +fn extend_search_next(cx: &mut CommandContext) { search_next_or_prev_impl(cx, Movement::Extend, Direction::Forward); } -fn extend_search_prev(cx: &mut Context) { +fn extend_search_prev(cx: &mut CommandContext) { search_next_or_prev_impl(cx, Movement::Extend, Direction::Backward); } -fn search_selection(cx: &mut Context) { +fn search_selection(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let contents = doc.text().slice(..); @@ -1923,7 +1923,7 @@ fn search_selection(cx: &mut Context) { cx.editor.set_status(msg); } -fn make_search_word_bounded(cx: &mut Context) { +fn make_search_word_bounded(cx: &mut CommandContext) { let regex = match cx.editor.registers.last('/') { Some(regex) => regex, None => return, @@ -1952,7 +1952,7 @@ fn make_search_word_bounded(cx: &mut Context) { cx.editor.set_status(msg); } -fn global_search(cx: &mut Context) { +fn global_search(cx: &mut CommandContext) { #[derive(Debug)] struct FileResult { path: PathBuf, @@ -2143,7 +2143,7 @@ enum Extend { Below, } -fn extend_line(cx: &mut Context) { +fn extend_line(cx: &mut CommandContext) { let (view, doc) = current_ref!(cx.editor); let extend = match doc.selection(view.id).primary().direction() { Direction::Forward => Extend::Below, @@ -2152,15 +2152,15 @@ fn extend_line(cx: &mut Context) { extend_line_impl(cx, extend); } -fn extend_line_below(cx: &mut Context) { +fn extend_line_below(cx: &mut CommandContext) { extend_line_impl(cx, Extend::Below); } -fn extend_line_above(cx: &mut Context) { +fn extend_line_above(cx: &mut CommandContext) { extend_line_impl(cx, Extend::Above); } -fn extend_line_impl(cx: &mut Context, extend: Extend) { +fn extend_line_impl(cx: &mut CommandContext, extend: Extend) { let count = cx.count(); let (view, doc) = current!(cx.editor); @@ -2199,7 +2199,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) { doc.set_selection(view.id, selection); } -fn extend_to_line_bounds(cx: &mut Context) { +fn extend_to_line_bounds(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); doc.set_selection( @@ -2216,7 +2216,7 @@ fn extend_to_line_bounds(cx: &mut Context) { ); } -fn shrink_to_line_bounds(cx: &mut Context) { +fn shrink_to_line_bounds(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); doc.set_selection( @@ -2258,7 +2258,7 @@ enum Operation { Change, } -fn delete_selection_impl(cx: &mut Context, op: Operation) { +fn delete_selection_impl(cx: &mut CommandContext, op: Operation) { let (view, doc) = current!(cx.editor); let selection = doc.selection(view.id); @@ -2296,25 +2296,25 @@ fn delete_selection_insert_mode(doc: &mut Document, view: &mut View, selection: doc.apply(&transaction, view.id); } -fn delete_selection(cx: &mut Context) { +fn delete_selection(cx: &mut CommandContext) { delete_selection_impl(cx, Operation::Delete); } -fn delete_selection_noyank(cx: &mut Context) { +fn delete_selection_noyank(cx: &mut CommandContext) { cx.register = Some('_'); delete_selection_impl(cx, Operation::Delete); } -fn change_selection(cx: &mut Context) { +fn change_selection(cx: &mut CommandContext) { delete_selection_impl(cx, Operation::Change); } -fn change_selection_noyank(cx: &mut Context) { +fn change_selection_noyank(cx: &mut CommandContext) { cx.register = Some('_'); delete_selection_impl(cx, Operation::Change); } -fn collapse_selection(cx: &mut Context) { +fn collapse_selection(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -2325,7 +2325,7 @@ fn collapse_selection(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn flip_selections(cx: &mut Context) { +fn flip_selections(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let selection = doc @@ -2335,7 +2335,7 @@ fn flip_selections(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn ensure_selections_forward(cx: &mut Context) { +fn ensure_selections_forward(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let selection = doc @@ -2346,12 +2346,12 @@ fn ensure_selections_forward(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn enter_insert_mode(cx: &mut Context) { +fn enter_insert_mode(cx: &mut CommandContext) { cx.editor.mode = Mode::Insert; } // inserts at the start of each selection -fn insert_mode(cx: &mut Context) { +fn insert_mode(cx: &mut CommandContext) { enter_insert_mode(cx); let (view, doc) = current!(cx.editor); @@ -2370,7 +2370,7 @@ fn insert_mode(cx: &mut Context) { } // inserts at the end of each selection -fn append_mode(cx: &mut Context) { +fn append_mode(cx: &mut CommandContext) { enter_insert_mode(cx); let (view, doc) = current!(cx.editor); doc.restore_cursor = true; @@ -2401,7 +2401,7 @@ fn append_mode(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn file_picker(cx: &mut Context) { +fn file_picker(cx: &mut CommandContext) { // We don't specify language markers, root will be the root of the current // git repo or the current dir if we're not in a repo let root = find_root(None, &[]); @@ -2409,7 +2409,7 @@ fn file_picker(cx: &mut Context) { cx.push_layer(Box::new(overlayed(picker))); } -fn file_picker_in_current_buffer_directory(cx: &mut Context) { +fn file_picker_in_current_buffer_directory(cx: &mut CommandContext) { let doc_dir = doc!(cx.editor) .path() .and_then(|path| path.parent().map(|path| path.to_path_buf())); @@ -2425,13 +2425,13 @@ fn file_picker_in_current_buffer_directory(cx: &mut Context) { let picker = ui::file_picker(path, &cx.editor.config()); cx.push_layer(Box::new(overlayed(picker))); } -fn file_picker_in_current_directory(cx: &mut Context) { +fn file_picker_in_current_directory(cx: &mut CommandContext) { let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("./")); let picker = ui::file_picker(cwd, &cx.editor.config()); cx.push_layer(Box::new(overlayed(picker))); } -fn buffer_picker(cx: &mut Context) { +fn buffer_picker(cx: &mut CommandContext) { let current = view!(cx.editor).doc; struct BufferMeta { @@ -2496,7 +2496,7 @@ fn buffer_picker(cx: &mut Context) { cx.push_layer(Box::new(overlayed(picker))); } -fn jumplist_picker(cx: &mut Context) { +fn jumplist_picker(cx: &mut CommandContext) { struct JumpMeta { id: DocumentId, path: Option, @@ -2607,7 +2607,7 @@ impl ui::menu::Item for MappableCommand { } } -pub fn command_palette(cx: &mut Context) { +pub fn command_palette(cx: &mut CommandContext) { cx.callback = Some(Box::new( move |compositor: &mut Compositor, cx: &mut compositor::CompositorContext| { let keymap = compositor.find::().unwrap().keymaps.map() @@ -2624,7 +2624,7 @@ pub fn command_palette(cx: &mut Context) { })); let picker = Picker::new(commands, keymap, move |cx, command, _action| { - let mut ctx = Context { + let mut ctx = CommandContext { register: None, count: std::num::NonZeroUsize::new(1), editor: cx.editor, @@ -2654,7 +2654,7 @@ pub fn command_palette(cx: &mut Context) { )); } -fn last_picker(cx: &mut Context) { +fn last_picker(cx: &mut CommandContext) { // TODO: last picker does not seem to work well with buffer_picker cx.callback = Some(Box::new(|compositor, cx| { if let Some(picker) = compositor.last_picker.take() { @@ -2666,13 +2666,13 @@ fn last_picker(cx: &mut Context) { } // I inserts at the first nonwhitespace character of each line with a selection -fn insert_at_line_start(cx: &mut Context) { +fn insert_at_line_start(cx: &mut CommandContext) { goto_first_nonwhitespace(cx); enter_insert_mode(cx); } // A inserts at the end of each line with a selection -fn insert_at_line_end(cx: &mut Context) { +fn insert_at_line_end(cx: &mut CommandContext) { enter_insert_mode(cx); let (view, doc) = current!(cx.editor); @@ -2736,7 +2736,7 @@ pub enum Open { Above, } -fn open(cx: &mut Context, open: Open) { +fn open(cx: &mut CommandContext, open: Open) { let count = cx.count(); enter_insert_mode(cx); let (view, doc) = current!(cx.editor); @@ -2807,16 +2807,16 @@ fn open(cx: &mut Context, open: Open) { } // o inserts a new line after each line with a selection -fn open_below(cx: &mut Context) { +fn open_below(cx: &mut CommandContext) { open(cx, Open::Below) } // O inserts a new line before each line with a selection -fn open_above(cx: &mut Context) { +fn open_above(cx: &mut CommandContext) { open(cx, Open::Above) } -fn normal_mode(cx: &mut Context) { +fn normal_mode(cx: &mut CommandContext) { cx.editor.enter_normal_mode(); } @@ -2826,7 +2826,7 @@ fn push_jump(view: &mut View, doc: &Document) { view.jumps.push(jump); } -fn goto_line(cx: &mut Context) { +fn goto_line(cx: &mut CommandContext) { goto_line_impl(cx.editor, cx.count) } @@ -2852,7 +2852,7 @@ fn goto_line_impl(editor: &mut Editor, count: Option) { } } -fn goto_last_line(cx: &mut Context) { +fn goto_last_line(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); let line_idx = if text.line(text.len_lines() - 1).len_chars() == 0 { @@ -2871,7 +2871,7 @@ fn goto_last_line(cx: &mut Context) { doc.set_selection(view.id, selection); } -fn goto_last_accessed_file(cx: &mut Context) { +fn goto_last_accessed_file(cx: &mut CommandContext) { let view = view_mut!(cx.editor); if let Some(alt) = view.docs_access_history.pop() { cx.editor.switch(alt, Action::Replace); @@ -2880,7 +2880,7 @@ fn goto_last_accessed_file(cx: &mut Context) { } } -fn goto_last_modification(cx: &mut Context) { +fn goto_last_modification(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let pos = doc.history.get_mut().last_edit_pos(); let text = doc.text().slice(..); @@ -2893,7 +2893,7 @@ fn goto_last_modification(cx: &mut Context) { } } -fn goto_last_modified_file(cx: &mut Context) { +fn goto_last_modified_file(cx: &mut CommandContext) { let view = view!(cx.editor); let alternate_file = view .last_modified_docs @@ -2907,7 +2907,7 @@ fn goto_last_modified_file(cx: &mut Context) { } } -fn select_mode(cx: &mut Context) { +fn select_mode(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -2928,13 +2928,13 @@ fn select_mode(cx: &mut Context) { cx.editor.mode = Mode::Select; } -fn exit_select_mode(cx: &mut Context) { +fn exit_select_mode(cx: &mut CommandContext) { if cx.editor.mode == Mode::Select { cx.editor.mode = Mode::Normal; } } -fn goto_first_diag(cx: &mut Context) { +fn goto_first_diag(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let selection = match doc.diagnostics().first() { Some(diag) => Selection::single(diag.range.start, diag.range.end), @@ -2944,7 +2944,7 @@ fn goto_first_diag(cx: &mut Context) { align_view(doc, view, Align::Center); } -fn goto_last_diag(cx: &mut Context) { +fn goto_last_diag(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let selection = match doc.diagnostics().last() { Some(diag) => Selection::single(diag.range.start, diag.range.end), @@ -2954,7 +2954,7 @@ fn goto_last_diag(cx: &mut Context) { align_view(doc, view, Align::Center); } -fn goto_next_diag(cx: &mut Context) { +fn goto_next_diag(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let cursor_pos = doc @@ -2976,7 +2976,7 @@ fn goto_next_diag(cx: &mut Context) { align_view(doc, view, Align::Center); } -fn goto_prev_diag(cx: &mut Context) { +fn goto_prev_diag(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let cursor_pos = doc @@ -3001,15 +3001,15 @@ fn goto_prev_diag(cx: &mut Context) { align_view(doc, view, Align::Center); } -fn goto_first_change(cx: &mut Context) { +fn goto_first_change(cx: &mut CommandContext) { goto_first_change_impl(cx, false); } -fn goto_last_change(cx: &mut Context) { +fn goto_last_change(cx: &mut CommandContext) { goto_first_change_impl(cx, true); } -fn goto_first_change_impl(cx: &mut Context, reverse: bool) { +fn goto_first_change_impl(cx: &mut CommandContext, reverse: bool) { let editor = &mut cx.editor; let (view, doc) = current!(editor); if let Some(handle) = doc.diff_handle() { @@ -3029,15 +3029,15 @@ fn goto_first_change_impl(cx: &mut Context, reverse: bool) { } } -fn goto_next_change(cx: &mut Context) { +fn goto_next_change(cx: &mut CommandContext) { goto_next_change_impl(cx, Direction::Forward) } -fn goto_prev_change(cx: &mut Context) { +fn goto_prev_change(cx: &mut CommandContext) { goto_next_change_impl(cx, Direction::Backward) } -fn goto_next_change_impl(cx: &mut Context, direction: Direction) { +fn goto_next_change_impl(cx: &mut CommandContext, direction: Direction) { let count = cx.count() as u32 - 1; let motion = move |editor: &mut Editor| { let (view, doc) = current!(editor); @@ -3105,7 +3105,7 @@ fn hunk_range(hunk: Hunk, text: RopeSlice) -> Range { pub mod insert { use super::*; pub type Hook = fn(&Rope, &Selection, char) -> Option; - pub type PostHook = fn(&mut Context, char); + pub type PostHook = fn(&mut CommandContext, char); /// Exclude the cursor in range. fn exclude_cursor(text: RopeSlice, range: Range, cursor: Range) -> Range { @@ -3121,7 +3121,7 @@ pub mod insert { // It trigger completion when idle timer reaches deadline // Only trigger completion if the word under cursor is longer than n characters - pub fn idle_completion(cx: &mut Context) { + pub fn idle_completion(cx: &mut CommandContext) { let config = cx.editor.config(); let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -3139,7 +3139,7 @@ pub mod insert { super::completion(cx); } - fn language_server_completion(cx: &mut Context, ch: char) { + fn language_server_completion(cx: &mut CommandContext, ch: char) { let config = cx.editor.config(); if !config.auto_completion { return; @@ -3168,7 +3168,7 @@ pub mod insert { } } - fn signature_help(cx: &mut Context, ch: char) { + fn signature_help(cx: &mut CommandContext, ch: char) { use helix_lsp::lsp; // if ch matches signature_help char, trigger let doc = doc_mut!(cx.editor); @@ -3217,7 +3217,7 @@ pub mod insert { use helix_core::auto_pairs; - pub fn insert_char(cx: &mut Context, c: char) { + pub fn insert_char(cx: &mut CommandContext, c: char) { let (view, doc) = current_ref!(cx.editor); let text = doc.text(); let selection = doc.selection(view.id); @@ -3241,7 +3241,7 @@ pub mod insert { } } - pub fn insert_tab(cx: &mut Context) { + pub fn insert_tab(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); // TODO: round out to nearest indentation level (for example a line with 3 spaces should // indent by one to reach 4 spaces). @@ -3255,7 +3255,7 @@ pub mod insert { doc.apply(&transaction, view.id); } - pub fn insert_newline(cx: &mut Context) { + pub fn insert_newline(cx: &mut CommandContext) { let (view, doc) = current_ref!(cx.editor); let text = doc.text().slice(..); @@ -3360,7 +3360,7 @@ pub mod insert { doc.apply(&transaction, view.id); } - pub fn delete_char_backward(cx: &mut Context) { + pub fn delete_char_backward(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current_ref!(cx.editor); let text = doc.text().slice(..); @@ -3450,7 +3450,7 @@ pub mod insert { lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic); } - pub fn delete_char_forward(cx: &mut Context) { + pub fn delete_char_forward(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -3468,7 +3468,7 @@ pub mod insert { lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic); } - pub fn delete_word_backward(cx: &mut Context) { + pub fn delete_word_backward(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -3483,7 +3483,7 @@ pub mod insert { lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic); } - pub fn delete_word_forward(cx: &mut Context) { + pub fn delete_word_forward(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -3501,7 +3501,7 @@ pub mod insert { // Undo / Redo -fn undo(cx: &mut Context) { +fn undo(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); for _ in 0..count { @@ -3512,7 +3512,7 @@ fn undo(cx: &mut Context) { } } -fn redo(cx: &mut Context) { +fn redo(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); for _ in 0..count { @@ -3523,7 +3523,7 @@ fn redo(cx: &mut Context) { } } -fn earlier(cx: &mut Context) { +fn earlier(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); for _ in 0..count { @@ -3535,7 +3535,7 @@ fn earlier(cx: &mut Context) { } } -fn later(cx: &mut Context) { +fn later(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); for _ in 0..count { @@ -3547,14 +3547,14 @@ fn later(cx: &mut Context) { } } -fn commit_undo_checkpoint(cx: &mut Context) { +fn commit_undo_checkpoint(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); doc.append_changes_to_history(view); } // Yank / Paste -fn yank(cx: &mut Context) { +fn yank(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -3615,7 +3615,7 @@ fn yank_joined_to_clipboard_impl( Ok(()) } -fn yank_joined_to_clipboard(cx: &mut Context) { +fn yank_joined_to_clipboard(cx: &mut CommandContext) { let line_ending = doc!(cx.editor).line_ending; let _ = yank_joined_to_clipboard_impl(cx.editor, line_ending.as_str(), ClipboardType::Clipboard); @@ -3647,17 +3647,17 @@ fn yank_main_selection_to_clipboard_impl( Ok(()) } -fn yank_main_selection_to_clipboard(cx: &mut Context) { +fn yank_main_selection_to_clipboard(cx: &mut CommandContext) { let _ = yank_main_selection_to_clipboard_impl(cx.editor, ClipboardType::Clipboard); } -fn yank_joined_to_primary_clipboard(cx: &mut Context) { +fn yank_joined_to_primary_clipboard(cx: &mut CommandContext) { let line_ending = doc!(cx.editor).line_ending; let _ = yank_joined_to_clipboard_impl(cx.editor, line_ending.as_str(), ClipboardType::Selection); } -fn yank_main_selection_to_primary_clipboard(cx: &mut Context) { +fn yank_main_selection_to_primary_clipboard(cx: &mut CommandContext) { let _ = yank_main_selection_to_clipboard_impl(cx.editor, ClipboardType::Selection); exit_select_mode(cx); } @@ -3748,7 +3748,7 @@ fn paste_impl( doc.append_changes_to_history(view); } -pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) { +pub(crate) fn paste_bracketed_value(cx: &mut CommandContext, contents: String) { let count = cx.count(); let paste = match cx.editor.mode { Mode::Insert | Mode::Select => Paste::Cursor, @@ -3774,7 +3774,7 @@ fn paste_clipboard_impl( } } -fn paste_clipboard_after(cx: &mut Context) { +fn paste_clipboard_after(cx: &mut CommandContext) { let _ = paste_clipboard_impl( cx.editor, Paste::After, @@ -3783,7 +3783,7 @@ fn paste_clipboard_after(cx: &mut Context) { ); } -fn paste_clipboard_before(cx: &mut Context) { +fn paste_clipboard_before(cx: &mut CommandContext) { let _ = paste_clipboard_impl( cx.editor, Paste::Before, @@ -3792,7 +3792,7 @@ fn paste_clipboard_before(cx: &mut Context) { ); } -fn paste_primary_clipboard_after(cx: &mut Context) { +fn paste_primary_clipboard_after(cx: &mut CommandContext) { let _ = paste_clipboard_impl( cx.editor, Paste::After, @@ -3801,7 +3801,7 @@ fn paste_primary_clipboard_after(cx: &mut Context) { ); } -fn paste_primary_clipboard_before(cx: &mut Context) { +fn paste_primary_clipboard_before(cx: &mut CommandContext) { let _ = paste_clipboard_impl( cx.editor, Paste::Before, @@ -3810,7 +3810,7 @@ fn paste_primary_clipboard_before(cx: &mut Context) { ); } -fn replace_with_yanked(cx: &mut Context) { +fn replace_with_yanked(cx: &mut CommandContext) { let count = cx.count(); let reg_name = cx.register.unwrap_or('"'); let (view, doc) = current!(cx.editor); @@ -3844,7 +3844,7 @@ fn replace_with_yanked(cx: &mut Context) { } fn replace_selections_with_clipboard_impl( - cx: &mut Context, + cx: &mut CommandContext, clipboard_type: ClipboardType, ) -> anyhow::Result<()> { let count = cx.count(); @@ -3871,15 +3871,15 @@ fn replace_selections_with_clipboard_impl( Ok(()) } -fn replace_selections_with_clipboard(cx: &mut Context) { +fn replace_selections_with_clipboard(cx: &mut CommandContext) { let _ = replace_selections_with_clipboard_impl(cx, ClipboardType::Clipboard); } -fn replace_selections_with_primary_clipboard(cx: &mut Context) { +fn replace_selections_with_primary_clipboard(cx: &mut CommandContext) { let _ = replace_selections_with_clipboard_impl(cx, ClipboardType::Selection); } -fn paste(cx: &mut Context, pos: Paste) { +fn paste(cx: &mut CommandContext, pos: Paste) { let count = cx.count(); let reg_name = cx.register.unwrap_or('"'); let (view, doc) = current!(cx.editor); @@ -3890,11 +3890,11 @@ fn paste(cx: &mut Context, pos: Paste) { } } -fn paste_after(cx: &mut Context) { +fn paste_after(cx: &mut CommandContext) { paste(cx, Paste::After) } -fn paste_before(cx: &mut Context) { +fn paste_before(cx: &mut CommandContext) { paste(cx, Paste::Before) } @@ -3914,7 +3914,7 @@ fn get_lines(doc: &Document, view_id: ViewId) -> Vec { lines } -fn indent(cx: &mut Context) { +fn indent(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); let lines = get_lines(doc, view.id); @@ -3936,7 +3936,7 @@ fn indent(cx: &mut Context) { doc.apply(&transaction, view.id); } -fn unindent(cx: &mut Context) { +fn unindent(cx: &mut CommandContext) { let count = cx.count(); let (view, doc) = current!(cx.editor); let lines = get_lines(doc, view.id); @@ -3975,7 +3975,7 @@ fn unindent(cx: &mut Context) { doc.apply(&transaction, view.id); } -fn format_selections(cx: &mut Context) { +fn format_selections(cx: &mut CommandContext) { use helix_lsp::{lsp, util::range_to_lsp_range}; let (view, doc) = current!(cx.editor); @@ -4030,7 +4030,7 @@ fn format_selections(cx: &mut Context) { doc.apply(&transaction, view.id); } -fn join_selections_impl(cx: &mut Context, select_space: bool) { +fn join_selections_impl(cx: &mut CommandContext, select_space: bool) { use movement::skip_while; let (view, doc) = current!(cx.editor); let text = doc.text(); @@ -4089,7 +4089,7 @@ fn join_selections_impl(cx: &mut Context, select_space: bool) { doc.apply(&transaction, view.id); } -fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) { +fn keep_or_remove_selections_impl(cx: &mut CommandContext, remove: bool) { // keep or remove selections matching regex let reg = cx.register.unwrap_or('/'); ui::regex_prompt( @@ -4113,23 +4113,23 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) { ) } -fn join_selections(cx: &mut Context) { +fn join_selections(cx: &mut CommandContext) { join_selections_impl(cx, false) } -fn join_selections_space(cx: &mut Context) { +fn join_selections_space(cx: &mut CommandContext) { join_selections_impl(cx, true) } -fn keep_selections(cx: &mut Context) { +fn keep_selections(cx: &mut CommandContext) { keep_or_remove_selections_impl(cx, false) } -fn remove_selections(cx: &mut Context) { +fn remove_selections(cx: &mut CommandContext) { keep_or_remove_selections_impl(cx, true) } -fn keep_primary_selection(cx: &mut Context) { +fn keep_primary_selection(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); // TODO: handle count @@ -4137,7 +4137,7 @@ fn keep_primary_selection(cx: &mut Context) { doc.set_selection(view.id, Selection::single(range.anchor, range.head)); } -fn remove_primary_selection(cx: &mut Context) { +fn remove_primary_selection(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); // TODO: handle count @@ -4152,7 +4152,7 @@ fn remove_primary_selection(cx: &mut Context) { doc.set_selection(view.id, selection); } -pub fn completion(cx: &mut Context) { +pub fn completion(cx: &mut CommandContext) { use helix_lsp::{lsp, util::pos_to_lsp_pos}; let (view, doc) = current!(cx.editor); @@ -4221,7 +4221,7 @@ pub fn completion(cx: &mut Context) { } // comments -fn toggle_comments(cx: &mut Context) { +fn toggle_comments(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let token = doc .language_config() @@ -4233,7 +4233,7 @@ fn toggle_comments(cx: &mut Context) { exit_select_mode(cx); } -fn rotate_selections(cx: &mut Context, direction: Direction) { +fn rotate_selections(cx: &mut CommandContext, direction: Direction) { let count = cx.count(); let (view, doc) = current!(cx.editor); let mut selection = doc.selection(view.id).clone(); @@ -4245,14 +4245,14 @@ fn rotate_selections(cx: &mut Context, direction: Direction) { }); doc.set_selection(view.id, selection); } -fn rotate_selections_forward(cx: &mut Context) { +fn rotate_selections_forward(cx: &mut CommandContext) { rotate_selections(cx, Direction::Forward) } -fn rotate_selections_backward(cx: &mut Context) { +fn rotate_selections_backward(cx: &mut CommandContext) { rotate_selections(cx, Direction::Backward) } -fn rotate_selection_contents(cx: &mut Context, direction: Direction) { +fn rotate_selection_contents(cx: &mut CommandContext, direction: Direction) { let count = cx.count; let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -4288,16 +4288,16 @@ fn rotate_selection_contents(cx: &mut Context, direction: Direction) { doc.apply(&transaction, view.id); } -fn rotate_selection_contents_forward(cx: &mut Context) { +fn rotate_selection_contents_forward(cx: &mut CommandContext) { rotate_selection_contents(cx, Direction::Forward) } -fn rotate_selection_contents_backward(cx: &mut Context) { +fn rotate_selection_contents_backward(cx: &mut CommandContext) { rotate_selection_contents(cx, Direction::Backward) } // tree sitter node selection -fn expand_selection(cx: &mut Context) { +fn expand_selection(cx: &mut CommandContext) { let motion = |editor: &mut Editor| { let (view, doc) = current!(editor); @@ -4320,7 +4320,7 @@ fn expand_selection(cx: &mut Context) { cx.editor.last_motion = Some(Motion(Box::new(motion))); } -fn shrink_selection(cx: &mut Context) { +fn shrink_selection(cx: &mut CommandContext) { let motion = |editor: &mut Editor| { let (view, doc) = current!(editor); let current_selection = doc.selection(view.id); @@ -4346,7 +4346,7 @@ fn shrink_selection(cx: &mut Context) { cx.editor.last_motion = Some(Motion(Box::new(motion))); } -fn select_sibling_impl(cx: &mut Context, sibling_fn: &'static F) +fn select_sibling_impl(cx: &mut CommandContext, sibling_fn: &'static F) where F: Fn(Node) -> Option, { @@ -4365,15 +4365,15 @@ where cx.editor.last_motion = Some(Motion(Box::new(motion))); } -fn select_next_sibling(cx: &mut Context) { +fn select_next_sibling(cx: &mut CommandContext) { select_sibling_impl(cx, &|node| Node::next_sibling(&node)) } -fn select_prev_sibling(cx: &mut Context) { +fn select_prev_sibling(cx: &mut CommandContext) { select_sibling_impl(cx, &|node| Node::prev_sibling(&node)) } -fn match_brackets(cx: &mut Context) { +fn match_brackets(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); if let Some(syntax) = doc.syntax() { @@ -4393,7 +4393,7 @@ fn match_brackets(cx: &mut Context) { // -fn jump_forward(cx: &mut Context) { +fn jump_forward(cx: &mut CommandContext) { let count = cx.count(); let config = cx.editor.config(); let view = view_mut!(cx.editor); @@ -4413,7 +4413,7 @@ fn jump_forward(cx: &mut Context) { }; } -fn jump_backward(cx: &mut Context) { +fn jump_backward(cx: &mut CommandContext) { let count = cx.count(); let config = cx.editor.config(); let (view, doc) = current!(cx.editor); @@ -4433,58 +4433,58 @@ fn jump_backward(cx: &mut Context) { }; } -fn save_selection(cx: &mut Context) { +fn save_selection(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); push_jump(view, doc); cx.editor.set_status("Selection saved to jumplist"); } -fn rotate_view(cx: &mut Context) { +fn rotate_view(cx: &mut CommandContext) { cx.editor.focus_next() } -fn rotate_view_reverse(cx: &mut Context) { +fn rotate_view_reverse(cx: &mut CommandContext) { cx.editor.focus_prev() } -fn jump_view_right(cx: &mut Context) { +fn jump_view_right(cx: &mut CommandContext) { cx.editor.focus_direction(tree::Direction::Right) } -fn jump_view_left(cx: &mut Context) { +fn jump_view_left(cx: &mut CommandContext) { cx.editor.focus_direction(tree::Direction::Left) } -fn jump_view_up(cx: &mut Context) { +fn jump_view_up(cx: &mut CommandContext) { cx.editor.focus_direction(tree::Direction::Up) } -fn jump_view_down(cx: &mut Context) { +fn jump_view_down(cx: &mut CommandContext) { cx.editor.focus_direction(tree::Direction::Down) } -fn swap_view_right(cx: &mut Context) { +fn swap_view_right(cx: &mut CommandContext) { cx.editor.swap_split_in_direction(tree::Direction::Right) } -fn swap_view_left(cx: &mut Context) { +fn swap_view_left(cx: &mut CommandContext) { cx.editor.swap_split_in_direction(tree::Direction::Left) } -fn swap_view_up(cx: &mut Context) { +fn swap_view_up(cx: &mut CommandContext) { cx.editor.swap_split_in_direction(tree::Direction::Up) } -fn swap_view_down(cx: &mut Context) { +fn swap_view_down(cx: &mut CommandContext) { cx.editor.swap_split_in_direction(tree::Direction::Down) } -fn transpose_view(cx: &mut Context) { +fn transpose_view(cx: &mut CommandContext) { cx.editor.transpose_view() } // split helper, clear it later -fn split(cx: &mut Context, action: Action) { +fn split(cx: &mut CommandContext, action: Action) { let (view, doc) = current!(cx.editor); let id = doc.id(); let selection = doc.selection(view.id).clone(); @@ -4500,23 +4500,23 @@ fn split(cx: &mut Context, action: Action) { view.offset = offset; } -fn hsplit(cx: &mut Context) { +fn hsplit(cx: &mut CommandContext) { split(cx, Action::HorizontalSplit); } -fn hsplit_new(cx: &mut Context) { +fn hsplit_new(cx: &mut CommandContext) { cx.editor.new_file(Action::HorizontalSplit); } -fn vsplit(cx: &mut Context) { +fn vsplit(cx: &mut CommandContext) { split(cx, Action::VerticalSplit); } -fn vsplit_new(cx: &mut Context) { +fn vsplit_new(cx: &mut CommandContext) { cx.editor.new_file(Action::VerticalSplit); } -fn wclose(cx: &mut Context) { +fn wclose(cx: &mut CommandContext) { if cx.editor.tree.views().count() == 1 { if let Err(err) = typed::buffers_remaining_impl(cx.editor) { cx.editor.set_error(err.to_string()); @@ -4528,7 +4528,7 @@ fn wclose(cx: &mut Context) { cx.editor.close(view_id); } -fn wonly(cx: &mut Context) { +fn wonly(cx: &mut CommandContext) { let views = cx .editor .tree @@ -4542,7 +4542,7 @@ fn wonly(cx: &mut Context) { } } -fn select_register(cx: &mut Context) { +fn select_register(cx: &mut CommandContext) { cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers)); cx.on_next_key(move |cx, event| { if let Some(ch) = event.char() { @@ -4552,7 +4552,7 @@ fn select_register(cx: &mut Context) { }) } -fn insert_register(cx: &mut Context) { +fn insert_register(cx: &mut CommandContext) { cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers)); cx.on_next_key(move |cx, event| { if let Some(ch) = event.char() { @@ -4563,22 +4563,22 @@ fn insert_register(cx: &mut Context) { }) } -fn align_view_top(cx: &mut Context) { +fn align_view_top(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); align_view(doc, view, Align::Top); } -fn align_view_center(cx: &mut Context) { +fn align_view_center(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); align_view(doc, view, Align::Center); } -fn align_view_bottom(cx: &mut Context) { +fn align_view_bottom(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); align_view(doc, view, Align::Bottom); } -fn align_view_middle(cx: &mut Context) { +fn align_view_middle(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let inner_width = view.inner_width(doc); let text_fmt = doc.text_format(inner_width, None); @@ -4597,15 +4597,15 @@ fn align_view_middle(cx: &mut Context) { .saturating_sub((view.inner_area(doc).width as usize) / 2); } -fn scroll_up(cx: &mut Context) { +fn scroll_up(cx: &mut CommandContext) { scroll(cx, cx.count(), Direction::Backward); } -fn scroll_down(cx: &mut Context) { +fn scroll_down(cx: &mut CommandContext) { scroll(cx, cx.count(), Direction::Forward); } -fn goto_ts_object_impl(cx: &mut Context, object: &'static str, direction: Direction) { +fn goto_ts_object_impl(cx: &mut CommandContext, object: &'static str, direction: Direction) { let count = cx.count(); let motion = move |editor: &mut Editor| { let (view, doc) = current!(editor); @@ -4646,55 +4646,55 @@ fn goto_ts_object_impl(cx: &mut Context, object: &'static str, direction: Direct cx.editor.last_motion = Some(Motion(Box::new(motion))); } -fn goto_next_function(cx: &mut Context) { +fn goto_next_function(cx: &mut CommandContext) { goto_ts_object_impl(cx, "function", Direction::Forward) } -fn goto_prev_function(cx: &mut Context) { +fn goto_prev_function(cx: &mut CommandContext) { goto_ts_object_impl(cx, "function", Direction::Backward) } -fn goto_next_class(cx: &mut Context) { +fn goto_next_class(cx: &mut CommandContext) { goto_ts_object_impl(cx, "class", Direction::Forward) } -fn goto_prev_class(cx: &mut Context) { +fn goto_prev_class(cx: &mut CommandContext) { goto_ts_object_impl(cx, "class", Direction::Backward) } -fn goto_next_parameter(cx: &mut Context) { +fn goto_next_parameter(cx: &mut CommandContext) { goto_ts_object_impl(cx, "parameter", Direction::Forward) } -fn goto_prev_parameter(cx: &mut Context) { +fn goto_prev_parameter(cx: &mut CommandContext) { goto_ts_object_impl(cx, "parameter", Direction::Backward) } -fn goto_next_comment(cx: &mut Context) { +fn goto_next_comment(cx: &mut CommandContext) { goto_ts_object_impl(cx, "comment", Direction::Forward) } -fn goto_prev_comment(cx: &mut Context) { +fn goto_prev_comment(cx: &mut CommandContext) { goto_ts_object_impl(cx, "comment", Direction::Backward) } -fn goto_next_test(cx: &mut Context) { +fn goto_next_test(cx: &mut CommandContext) { goto_ts_object_impl(cx, "test", Direction::Forward) } -fn goto_prev_test(cx: &mut Context) { +fn goto_prev_test(cx: &mut CommandContext) { goto_ts_object_impl(cx, "test", Direction::Backward) } -fn select_textobject_around(cx: &mut Context) { +fn select_textobject_around(cx: &mut CommandContext) { select_textobject(cx, textobject::TextObject::Around); } -fn select_textobject_inner(cx: &mut Context) { +fn select_textobject_inner(cx: &mut CommandContext) { select_textobject(cx, textobject::TextObject::Inside); } -fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { +fn select_textobject(cx: &mut CommandContext, objtype: textobject::TextObject) { let count = cx.count(); cx.on_next_key(move |cx, event| { @@ -4790,7 +4790,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { cx.editor.autoinfo = Some(Info::new(title, &help_text)); } -fn surround_add(cx: &mut Context) { +fn surround_add(cx: &mut CommandContext) { cx.on_next_key(move |cx, event| { let (view, doc) = current!(cx.editor); // surround_len is the number of new characters being added. @@ -4835,7 +4835,7 @@ fn surround_add(cx: &mut Context) { }) } -fn surround_replace(cx: &mut Context) { +fn surround_replace(cx: &mut CommandContext) { let count = cx.count(); cx.on_next_key(move |cx, event| { let surround_ch = match event.char() { @@ -4876,7 +4876,7 @@ fn surround_replace(cx: &mut Context) { }) } -fn surround_delete(cx: &mut Context) { +fn surround_delete(cx: &mut CommandContext) { let count = cx.count(); cx.on_next_key(move |cx, event| { let surround_ch = match event.char() { @@ -4911,23 +4911,23 @@ enum ShellBehavior { Append, } -fn shell_pipe(cx: &mut Context) { +fn shell_pipe(cx: &mut CommandContext) { shell_prompt(cx, "pipe:".into(), ShellBehavior::Replace); } -fn shell_pipe_to(cx: &mut Context) { +fn shell_pipe_to(cx: &mut CommandContext) { shell_prompt(cx, "pipe-to:".into(), ShellBehavior::Ignore); } -fn shell_insert_output(cx: &mut Context) { +fn shell_insert_output(cx: &mut CommandContext) { shell_prompt(cx, "insert-output:".into(), ShellBehavior::Insert); } -fn shell_append_output(cx: &mut Context) { +fn shell_append_output(cx: &mut CommandContext) { shell_prompt(cx, "append-output:".into(), ShellBehavior::Append); } -fn shell_keep_pipe(cx: &mut Context) { +fn shell_keep_pipe(cx: &mut CommandContext) { ui::prompt( cx, "keep-pipe:".into(), @@ -5125,7 +5125,7 @@ fn shell(cx: &mut compositor::CompositorContext, cmd: &str, behavior: &ShellBeha view.ensure_cursor_in_view(doc, config.scrolloff); } -fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) { +fn shell_prompt(cx: &mut CommandContext, prompt: Cow<'static, str>, behavior: ShellBehavior) { ui::prompt( cx, prompt, @@ -5144,20 +5144,20 @@ fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBeha ); } -fn suspend(_cx: &mut Context) { +fn suspend(_cx: &mut CommandContext) { #[cfg(not(windows))] signal_hook::low_level::raise(signal_hook::consts::signal::SIGTSTP).unwrap(); } -fn add_newline_above(cx: &mut Context) { +fn add_newline_above(cx: &mut CommandContext) { add_newline_impl(cx, Open::Above); } -fn add_newline_below(cx: &mut Context) { +fn add_newline_below(cx: &mut CommandContext) { add_newline_impl(cx, Open::Below) } -fn add_newline_impl(cx: &mut Context, open: Open) { +fn add_newline_impl(cx: &mut CommandContext, open: Open) { let count = cx.count(); let (view, doc) = current!(cx.editor); let selection = doc.selection(view.id); @@ -5188,18 +5188,18 @@ enum IncrementDirection { } /// Increment objects within selections by count. -fn increment(cx: &mut Context) { +fn increment(cx: &mut CommandContext) { increment_impl(cx, IncrementDirection::Increase); } /// Decrement objects within selections by count. -fn decrement(cx: &mut Context) { +fn decrement(cx: &mut CommandContext) { increment_impl(cx, IncrementDirection::Decrease); } /// Increment objects within selections by `amount`. /// A negative `amount` will decrement objects within selections. -fn increment_impl(cx: &mut Context, increment_direction: IncrementDirection) { +fn increment_impl(cx: &mut CommandContext, increment_direction: IncrementDirection) { let sign = match increment_direction { IncrementDirection::Increase => 1, IncrementDirection::Decrease => -1, @@ -5250,7 +5250,7 @@ fn increment_impl(cx: &mut Context, increment_direction: IncrementDirection) { } } -fn record_macro(cx: &mut Context) { +fn record_macro(cx: &mut CommandContext) { if let Some((reg, mut keys)) = cx.editor.macro_recording.take() { // Remove the keypress which ends the recording keys.pop(); @@ -5276,7 +5276,7 @@ fn record_macro(cx: &mut Context) { } } -fn replay_macro(cx: &mut Context) { +fn replay_macro(cx: &mut CommandContext) { let reg = cx.register.unwrap_or('@'); if cx.editor.macro_replaying.contains(®) { diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index bc69c3c82124..e6862f37a0ef 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -1,4 +1,4 @@ -use super::{Context, Editor}; +use super::{CommandContext, Editor}; use crate::{ compositor::{self, Compositor}, job::{Callback, Jobs}, @@ -55,7 +55,7 @@ impl ui::menu::Item for Thread { } fn thread_picker( - cx: &mut Context, + cx: &mut CommandContext, callback_fn: impl Fn(&mut Editor, &dap::Thread) + Send + 'static, ) { let debugger = debugger!(cx.editor); @@ -248,7 +248,7 @@ pub fn dap_start_impl( Ok(()) } -pub fn dap_launch(cx: &mut Context) { +pub fn dap_launch(cx: &mut CommandContext) { if cx.editor.debugger.is_some() { cx.editor.set_error("Debugger is already running"); return; @@ -356,7 +356,7 @@ fn debug_parameter_prompt( ) } -pub fn dap_toggle_breakpoint(cx: &mut Context) { +pub fn dap_toggle_breakpoint(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let path = match doc.path() { Some(path) => path.clone(), @@ -371,7 +371,7 @@ pub fn dap_toggle_breakpoint(cx: &mut Context) { dap_toggle_breakpoint_impl(cx, path, line); } -pub fn dap_toggle_breakpoint_impl(cx: &mut Context, path: PathBuf, line: usize) { +pub fn dap_toggle_breakpoint_impl(cx: &mut CommandContext, path: PathBuf, line: usize) { // TODO: need to map breakpoints over edits and update them? // we shouldn't really allow editing while debug is running though @@ -397,7 +397,7 @@ pub fn dap_toggle_breakpoint_impl(cx: &mut Context, path: PathBuf, line: usize) } } -pub fn dap_continue(cx: &mut Context) { +pub fn dap_continue(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); if let Some(thread_id) = debugger.thread_id { @@ -416,7 +416,7 @@ pub fn dap_continue(cx: &mut Context) { } } -pub fn dap_pause(cx: &mut Context) { +pub fn dap_pause(cx: &mut CommandContext) { thread_picker(cx, |editor, thread| { let debugger = debugger!(editor); let request = debugger.pause(thread.id); @@ -427,7 +427,7 @@ pub fn dap_pause(cx: &mut Context) { }) } -pub fn dap_step_in(cx: &mut Context) { +pub fn dap_step_in(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); if let Some(thread_id) = debugger.thread_id { @@ -442,7 +442,7 @@ pub fn dap_step_in(cx: &mut Context) { } } -pub fn dap_step_out(cx: &mut Context) { +pub fn dap_step_out(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); if let Some(thread_id) = debugger.thread_id { @@ -456,7 +456,7 @@ pub fn dap_step_out(cx: &mut Context) { } } -pub fn dap_next(cx: &mut Context) { +pub fn dap_next(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); if let Some(thread_id) = debugger.thread_id { @@ -470,7 +470,7 @@ pub fn dap_next(cx: &mut Context) { } } -pub fn dap_variables(cx: &mut Context) { +pub fn dap_variables(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); if debugger.thread_id.is_none() { @@ -536,7 +536,7 @@ pub fn dap_variables(cx: &mut Context) { cx.push_layer(Box::new(popup)); } -pub fn dap_terminate(cx: &mut Context) { +pub fn dap_terminate(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); let request = debugger.disconnect(); @@ -546,7 +546,7 @@ pub fn dap_terminate(cx: &mut Context) { }); } -pub fn dap_enable_exceptions(cx: &mut Context) { +pub fn dap_enable_exceptions(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); let filters = match &debugger.capabilities().exception_breakpoint_filters { @@ -565,7 +565,7 @@ pub fn dap_enable_exceptions(cx: &mut Context) { ) } -pub fn dap_disable_exceptions(cx: &mut Context) { +pub fn dap_disable_exceptions(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); let request = debugger.set_exception_breakpoints(Vec::new()); @@ -580,7 +580,7 @@ pub fn dap_disable_exceptions(cx: &mut Context) { } // TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets -pub fn dap_edit_condition(cx: &mut Context) { +pub fn dap_edit_condition(cx: &mut CommandContext) { if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) { let path = match doc!(cx.editor).path() { Some(path) => path.clone(), @@ -622,7 +622,7 @@ pub fn dap_edit_condition(cx: &mut Context) { } } -pub fn dap_edit_log(cx: &mut Context) { +pub fn dap_edit_log(cx: &mut CommandContext) { if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) { let path = match doc!(cx.editor).path() { Some(path) => path.clone(), @@ -663,12 +663,12 @@ pub fn dap_edit_log(cx: &mut Context) { } } -pub fn dap_switch_thread(cx: &mut Context) { +pub fn dap_switch_thread(cx: &mut CommandContext) { thread_picker(cx, |editor, thread| { block_on(select_thread_id(editor, thread.id, true)); }) } -pub fn dap_switch_stack_frame(cx: &mut Context) { +pub fn dap_switch_stack_frame(cx: &mut CommandContext) { let debugger = debugger!(cx.editor); let thread_id = match debugger.thread_id { diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 1dd74aba3c5c..29bddf9d2a2d 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -13,7 +13,7 @@ use tui::{ widgets::Row, }; -use super::{align_view, push_jump, Align, Context, Editor, Open}; +use super::{align_view, push_jump, Align, CommandContext, Editor, Open}; use helix_core::{path, Selection}; use helix_view::{document::Mode, editor::Action, theme::Style}; @@ -262,7 +262,7 @@ enum DiagnosticsFormat { } fn diag_picker( - cx: &Context, + cx: &CommandContext, diagnostics: BTreeMap>, current_path: Option, format: DiagnosticsFormat, @@ -318,7 +318,7 @@ fn diag_picker( .truncate_start(false) } -pub fn symbol_picker(cx: &mut Context) { +pub fn symbol_picker(cx: &mut CommandContext) { fn nested_to_flat( list: &mut Vec, file: &lsp::TextDocumentIdentifier, @@ -377,7 +377,7 @@ pub fn symbol_picker(cx: &mut Context) { ) } -pub fn workspace_symbol_picker(cx: &mut Context) { +pub fn workspace_symbol_picker(cx: &mut CommandContext) { let doc = doc!(cx.editor); let current_url = doc.url(); let language_server = language_server!(cx.editor, doc); @@ -435,7 +435,7 @@ pub fn workspace_symbol_picker(cx: &mut Context) { ) } -pub fn diagnostics_picker(cx: &mut Context) { +pub fn diagnostics_picker(cx: &mut CommandContext) { let doc = doc!(cx.editor); let language_server = language_server!(cx.editor, doc); if let Some(current_url) = doc.url() { @@ -457,7 +457,7 @@ pub fn diagnostics_picker(cx: &mut Context) { } } -pub fn workspace_diagnostics_picker(cx: &mut Context) { +pub fn workspace_diagnostics_picker(cx: &mut CommandContext) { let doc = doc!(cx.editor); let language_server = language_server!(cx.editor, doc); let current_url = doc.url(); @@ -540,7 +540,7 @@ fn action_fixes_diagnostics(action: &CodeActionOrCommand) -> bool { ) } -pub fn code_action(cx: &mut Context) { +pub fn code_action(cx: &mut CommandContext) { let (view, doc) = current!(cx.editor); let language_server = language_server!(cx.editor, doc); @@ -919,7 +919,7 @@ fn to_locations(definitions: Option) -> Vec bool { + pub fn ensure_item_resolved(&mut self, cx: &mut commands::CommandContext) -> bool { // > If computing full completion items is expensive, servers can additionally provide a // > handler for the completion item resolve request. ... // > A typical use case is for example: the `textDocument/completion` request doesn't fill diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 027e001cff55..4e880915a9ba 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -794,7 +794,7 @@ impl EditorView { fn handle_keymap_event( &mut self, mode: Mode, - cxt: &mut commands::Context, + cxt: &mut commands::CommandContext, event: KeyEvent, ) -> Option { let mut last_mode = mode; @@ -850,7 +850,7 @@ impl EditorView { None } - fn insert_mode(&mut self, cx: &mut commands::Context, event: KeyEvent) { + fn insert_mode(&mut self, cx: &mut commands::CommandContext, event: KeyEvent) { if let Some(keyresult) = self.handle_keymap_event(Mode::Insert, cx, event) { match keyresult { KeymapResult::NotFound => { @@ -877,7 +877,7 @@ impl EditorView { } } - fn command_mode(&mut self, mode: Mode, cxt: &mut commands::Context, event: KeyEvent) { + fn command_mode(&mut self, mode: Mode, cxt: &mut commands::CommandContext, event: KeyEvent) { match (event, cxt.editor.count) { // count handling (key!(i @ '0'), Some(_)) | (key!(i @ '1'..='9'), _) => { @@ -977,7 +977,7 @@ impl EditorView { editor.clear_idle_timer(); // don't retrigger } - pub fn handle_idle_timeout(&mut self, cx: &mut commands::Context) -> EventResult { + pub fn handle_idle_timeout(&mut self, cx: &mut commands::CommandContext) -> EventResult { if let Some(completion) = &mut self.completion { return if completion.ensure_item_resolved(cx) { EventResult::Consumed(None) @@ -1000,7 +1000,7 @@ impl EditorView { fn handle_mouse_event( &mut self, event: &MouseEvent, - cxt: &mut commands::Context, + cxt: &mut commands::CommandContext, ) -> EventResult { let config = cxt.editor.config(); let MouseEvent { @@ -1187,7 +1187,7 @@ impl Component for EditorView { event: &Event, context: &mut crate::compositor::CompositorContext, ) -> EventResult { - let mut cx = commands::Context { + let mut cx = commands::CommandContext { editor: context.editor, count: None, register: None, diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index e77e09118c74..7be62c0089ea 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -34,7 +34,7 @@ use helix_view::Editor; use std::path::PathBuf; pub fn prompt( - cx: &mut crate::commands::Context, + cx: &mut crate::commands::CommandContext, prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, @@ -47,7 +47,7 @@ pub fn prompt( } pub fn prompt_with_input( - cx: &mut crate::commands::Context, + cx: &mut crate::commands::CommandContext, prompt: std::borrow::Cow<'static, str>, input: String, history_register: Option, @@ -60,7 +60,7 @@ pub fn prompt_with_input( } pub fn regex_prompt( - cx: &mut crate::commands::Context, + cx: &mut crate::commands::CommandContext, prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, From 507fe489788a3a78817f2cf1157e954425733a90 Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sun, 19 Feb 2023 20:52:53 +0100 Subject: [PATCH 3/5] use import for commands::CommandContext --- helix-term/src/ui/completion.rs | 7 +++---- helix-term/src/ui/editor.rs | 14 +++++++------- helix-term/src/ui/mod.rs | 7 ++++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 95e19212cb73..0912afd098c6 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,4 +1,4 @@ -use crate::compositor::{Component, CompositorContext, Event, EventResult}; +use crate::{compositor::{Component, CompositorContext, Event, EventResult}, commands::CommandContext}; use helix_view::{ editor::CompleteAction, theme::{Modifier, Style}, @@ -11,7 +11,6 @@ use std::borrow::Cow; use helix_core::{Change, Transaction}; use helix_view::{graphics::Rect, Document, Editor}; -use crate::commands; use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent}; use helix_lsp::{lsp, util}; @@ -313,7 +312,7 @@ impl Completion { } } - pub fn update(&mut self, cx: &mut commands::CommandContext) { + pub fn update(&mut self, cx: &mut CommandContext) { self.recompute_filter(cx.editor) } @@ -327,7 +326,7 @@ impl Completion { /// Asynchronously requests that the currently selection completion item is /// resolved through LSP `completionItem/resolve`. - pub fn ensure_item_resolved(&mut self, cx: &mut commands::CommandContext) -> bool { + pub fn ensure_item_resolved(&mut self, cx: &mut CommandContext) -> bool { // > If computing full completion items is expensive, servers can additionally provide a // > handler for the completion item resolve request. ... // > A typical use case is for example: the `textDocument/completion` request doesn't fill diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 4e880915a9ba..46d6c98ffe26 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1,5 +1,5 @@ use crate::{ - commands::{self, OnKeyCallback}, + commands::{self, OnKeyCallback, CommandContext}, compositor::{Component, CompositorContext, Event, EventResult}, job::{self, Callback}, key, @@ -794,7 +794,7 @@ impl EditorView { fn handle_keymap_event( &mut self, mode: Mode, - cxt: &mut commands::CommandContext, + cxt: &mut CommandContext, event: KeyEvent, ) -> Option { let mut last_mode = mode; @@ -850,7 +850,7 @@ impl EditorView { None } - fn insert_mode(&mut self, cx: &mut commands::CommandContext, event: KeyEvent) { + fn insert_mode(&mut self, cx: &mut CommandContext, event: KeyEvent) { if let Some(keyresult) = self.handle_keymap_event(Mode::Insert, cx, event) { match keyresult { KeymapResult::NotFound => { @@ -877,7 +877,7 @@ impl EditorView { } } - fn command_mode(&mut self, mode: Mode, cxt: &mut commands::CommandContext, event: KeyEvent) { + fn command_mode(&mut self, mode: Mode, cxt: &mut CommandContext, event: KeyEvent) { match (event, cxt.editor.count) { // count handling (key!(i @ '0'), Some(_)) | (key!(i @ '1'..='9'), _) => { @@ -977,7 +977,7 @@ impl EditorView { editor.clear_idle_timer(); // don't retrigger } - pub fn handle_idle_timeout(&mut self, cx: &mut commands::CommandContext) -> EventResult { + pub fn handle_idle_timeout(&mut self, cx: &mut CommandContext) -> EventResult { if let Some(completion) = &mut self.completion { return if completion.ensure_item_resolved(cx) { EventResult::Consumed(None) @@ -1000,7 +1000,7 @@ impl EditorView { fn handle_mouse_event( &mut self, event: &MouseEvent, - cxt: &mut commands::CommandContext, + cxt: &mut CommandContext, ) -> EventResult { let config = cxt.editor.config(); let MouseEvent { @@ -1187,7 +1187,7 @@ impl Component for EditorView { event: &Event, context: &mut crate::compositor::CompositorContext, ) -> EventResult { - let mut cx = commands::CommandContext { + let mut cx = CommandContext { editor: context.editor, count: None, register: None, diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 7be62c0089ea..b028b9c5d549 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -14,6 +14,7 @@ mod spinner; mod statusline; mod text; +use crate::commands::CommandContext; use crate::compositor::{Component, Compositor}; use crate::filter_picker_entry; use crate::job::{self, Callback}; @@ -34,7 +35,7 @@ use helix_view::Editor; use std::path::PathBuf; pub fn prompt( - cx: &mut crate::commands::CommandContext, + cx: &mut CommandContext, prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, @@ -47,7 +48,7 @@ pub fn prompt( } pub fn prompt_with_input( - cx: &mut crate::commands::CommandContext, + cx: &mut CommandContext, prompt: std::borrow::Cow<'static, str>, input: String, history_register: Option, @@ -60,7 +61,7 @@ pub fn prompt_with_input( } pub fn regex_prompt( - cx: &mut crate::commands::CommandContext, + cx: &mut CommandContext, prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, From e460f87fb72f460bd862613211ee5a3ed5e57cc4 Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sun, 19 Feb 2023 21:19:54 +0100 Subject: [PATCH 4/5] use import for compositor::CompositorContext --- helix-term/src/application.rs | 8 +- helix-term/src/commands.rs | 8 +- helix-term/src/commands/dap.rs | 4 +- helix-term/src/commands/lsp.rs | 4 +- helix-term/src/commands/typed.rs | 168 +++++++++++++++---------------- helix-term/src/ui/editor.rs | 2 +- helix-term/src/ui/mod.rs | 8 +- 7 files changed, 101 insertions(+), 101 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 41ea7caa1c87..41ffefcbdda3 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -21,7 +21,7 @@ use tui::backend::Backend; use crate::{ args::Args, commands::apply_workspace_edit, - compositor::{Compositor, Event}, + compositor::{Compositor, Event, CompositorContext}, config::Config, job::Jobs, keymap::Keymaps, @@ -278,7 +278,7 @@ impl Application { } async fn render(&mut self) { - let mut cx = crate::compositor::CompositorContext { + let mut cx = CompositorContext { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, @@ -495,7 +495,7 @@ impl Application { } pub async fn handle_idle_timeout(&mut self) { - let mut cx = crate::compositor::CompositorContext { + let mut cx = CompositorContext { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, @@ -615,7 +615,7 @@ impl Application { &mut self, event: Result, ) { - let mut cx = crate::compositor::CompositorContext { + let mut cx = CompositorContext { editor: &mut self.editor, jobs: &mut self.jobs, scroll: None, diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a6fc62b01e72..232ecadcd7a6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -48,7 +48,7 @@ use movement::Movement; use crate::{ args, - compositor::{self, Component, Compositor}, + compositor::{self, Component, Compositor, CompositorContext}, filter_picker_entry, job::Callback, keymap::ReverseKeymap, @@ -172,7 +172,7 @@ impl MappableCommand { Self::Typable { name, args, doc: _ } => { let args: Vec> = args.iter().map(Cow::from).collect(); if let Some(command) = typed::TYPABLE_COMMAND_MAP.get(name.as_str()) { - let mut cx = compositor::CompositorContext { + let mut cx = CompositorContext { editor: cx.editor, jobs: cx.jobs, scroll: None, @@ -2609,7 +2609,7 @@ impl ui::menu::Item for MappableCommand { pub fn command_palette(cx: &mut CommandContext) { cx.callback = Some(Box::new( - move |compositor: &mut Compositor, cx: &mut compositor::CompositorContext| { + move |compositor: &mut Compositor, cx: &mut CompositorContext| { let keymap = compositor.find::().unwrap().keymaps.map() [&cx.editor.mode] .reverse_map(); @@ -5052,7 +5052,7 @@ async fn shell_impl_async( Ok((tendril, output.status.success())) } -fn shell(cx: &mut compositor::CompositorContext, cmd: &str, behavior: &ShellBehavior) { +fn shell(cx: &mut CompositorContext, cmd: &str, behavior: &ShellBehavior) { let pipe = match behavior { ShellBehavior::Replace | ShellBehavior::Ignore => true, ShellBehavior::Insert | ShellBehavior::Append => false, diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index e6862f37a0ef..27eaae014902 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -1,6 +1,6 @@ use super::{CommandContext, Editor}; use crate::{ - compositor::{self, Compositor}, + compositor::{Compositor, CompositorContext}, job::{Callback, Jobs}, ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent, Text}, }; @@ -130,7 +130,7 @@ fn dap_callback( } pub fn dap_start_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, name: Option<&str>, socket: Option, params: Option>>, diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 29bddf9d2a2d..8fc73f6691b2 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -19,7 +19,7 @@ use helix_core::{path, Selection}; use helix_view::{document::Mode, editor::Action, theme::Style}; use crate::{ - compositor::{self, Compositor}, + compositor::{Compositor, CompositorContext}, ui::{ self, lsp::SignatureHelp, overlay::overlayed, DynamicPicker, FileLocation, FilePicker, Popup, PromptEvent, @@ -1249,7 +1249,7 @@ pub fn rename_symbol(cx: &mut CommandContext) { prefill, None, ui::completers::none, - move |cx: &mut compositor::CompositorContext, input: &str, event: PromptEvent| { + move |cx: &mut CompositorContext, input: &str, event: PromptEvent| { if event != PromptEvent::Validate { return; } diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d01fef646b82..d7b0e407a38f 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -17,11 +17,11 @@ pub struct TypableCommand { pub aliases: &'static [&'static str], pub doc: &'static str, // params, flags, helper, completer - pub fun: fn(&mut compositor::CompositorContext, &[Cow], PromptEvent) -> anyhow::Result<()>, + pub fun: fn(&mut CompositorContext, &[Cow], PromptEvent) -> anyhow::Result<()>, pub completer: Option, } -fn quit(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn quit(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { log::debug!("quitting..."); if event != PromptEvent::Validate { @@ -42,7 +42,7 @@ fn quit(cx: &mut compositor::CompositorContext, args: &[Cow], event: Prompt } fn force_quit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -58,7 +58,7 @@ fn force_quit( Ok(()) } -fn open(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn open(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -94,7 +94,7 @@ fn open(cx: &mut compositor::CompositorContext, args: &[Cow], event: Prompt } fn buffer_close_by_ids_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, doc_ids: &[DocumentId], force: bool, ) -> anyhow::Result<()> { @@ -166,7 +166,7 @@ fn buffer_gather_paths_impl(editor: &mut Editor, args: &[Cow]) -> Vec], event: PromptEvent, ) -> anyhow::Result<()> { @@ -179,7 +179,7 @@ fn buffer_close( } fn force_buffer_close( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -201,7 +201,7 @@ fn buffer_gather_others_impl(editor: &mut Editor) -> Vec { } fn buffer_close_others( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -214,7 +214,7 @@ fn buffer_close_others( } fn force_buffer_close_others( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -231,7 +231,7 @@ fn buffer_gather_all_impl(editor: &mut Editor) -> Vec { } fn buffer_close_all( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -244,7 +244,7 @@ fn buffer_close_all( } fn force_buffer_close_all( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -257,7 +257,7 @@ fn force_buffer_close_all( } fn buffer_next( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -270,7 +270,7 @@ fn buffer_next( } fn buffer_previous( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -283,7 +283,7 @@ fn buffer_previous( } fn write_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, path: Option<&Cow>, force: bool, ) -> anyhow::Result<()> { @@ -317,7 +317,7 @@ fn write_impl( } fn write( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -329,7 +329,7 @@ fn write( } fn force_write( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -341,7 +341,7 @@ fn force_write( } fn new_file( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -355,7 +355,7 @@ fn new_file( } fn format( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -372,7 +372,7 @@ fn format( Ok(()) } fn set_indent_style( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -415,7 +415,7 @@ fn set_indent_style( /// Sets or reports the current document's line ending setting. fn set_line_ending( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -488,7 +488,7 @@ fn set_line_ending( } fn earlier( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -508,7 +508,7 @@ fn earlier( } fn later( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -527,7 +527,7 @@ fn later( } fn write_quit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -541,7 +541,7 @@ fn write_quit( } fn force_write_quit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -580,7 +580,7 @@ pub(super) fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()> } pub fn write_all_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, force: bool, write_scratch: bool, ) -> anyhow::Result<()> { @@ -656,7 +656,7 @@ pub fn write_all_impl( } fn write_all( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -668,7 +668,7 @@ fn write_all( } fn write_all_quit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -680,7 +680,7 @@ fn write_all_quit( } fn force_write_all_quit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -691,7 +691,7 @@ fn force_write_all_quit( quit_all_impl(cx, true) } -fn quit_all_impl(cx: &mut compositor::CompositorContext, force: bool) -> anyhow::Result<()> { +fn quit_all_impl(cx: &mut CompositorContext, force: bool) -> anyhow::Result<()> { cx.block_try_flush_writes()?; if !force { buffers_remaining_impl(cx.editor)?; @@ -707,7 +707,7 @@ fn quit_all_impl(cx: &mut compositor::CompositorContext, force: bool) -> anyhow: } fn quit_all( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -719,7 +719,7 @@ fn quit_all( } fn force_quit_all( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -731,7 +731,7 @@ fn force_quit_all( } fn cquit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -749,7 +749,7 @@ fn cquit( } fn force_cquit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -767,7 +767,7 @@ fn force_cquit( } fn theme( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -812,7 +812,7 @@ fn theme( } fn yank_main_selection_to_clipboard( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -824,7 +824,7 @@ fn yank_main_selection_to_clipboard( } fn yank_joined_to_clipboard( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -839,7 +839,7 @@ fn yank_joined_to_clipboard( } fn yank_main_selection_to_primary_clipboard( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -851,7 +851,7 @@ fn yank_main_selection_to_primary_clipboard( } fn yank_joined_to_primary_clipboard( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -866,7 +866,7 @@ fn yank_joined_to_primary_clipboard( } fn paste_clipboard_after( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -878,7 +878,7 @@ fn paste_clipboard_after( } fn paste_clipboard_before( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -890,7 +890,7 @@ fn paste_clipboard_before( } fn paste_primary_clipboard_after( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -902,7 +902,7 @@ fn paste_primary_clipboard_after( } fn paste_primary_clipboard_before( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -914,7 +914,7 @@ fn paste_primary_clipboard_before( } fn replace_selections_with_clipboard_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, clipboard_type: ClipboardType, ) -> anyhow::Result<()> { let scrolloff = cx.editor.config().scrolloff; @@ -937,7 +937,7 @@ fn replace_selections_with_clipboard_impl( } fn replace_selections_with_clipboard( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -949,7 +949,7 @@ fn replace_selections_with_clipboard( } fn replace_selections_with_primary_clipboard( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -961,7 +961,7 @@ fn replace_selections_with_primary_clipboard( } fn show_clipboard_provider( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -975,7 +975,7 @@ fn show_clipboard_provider( } fn change_current_directory( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1003,7 +1003,7 @@ fn change_current_directory( } fn show_current_directory( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1019,7 +1019,7 @@ fn show_current_directory( /// Sets the [`Document`]'s encoding.. fn set_encoding( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1039,7 +1039,7 @@ fn set_encoding( /// Shows info about the character under the primary cursor. fn get_character_info( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1164,7 +1164,7 @@ fn get_character_info( /// Reload the [`Document`] from its source file. fn reload( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1182,7 +1182,7 @@ fn reload( } fn reload_all( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1233,7 +1233,7 @@ fn reload_all( /// Update the [`Document`] if it has been modified. fn update( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1250,7 +1250,7 @@ fn update( } fn lsp_workspace_command( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1321,7 +1321,7 @@ fn lsp_workspace_command( } fn lsp_restart( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1355,7 +1355,7 @@ fn lsp_restart( } fn tree_sitter_scopes( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1388,7 +1388,7 @@ fn tree_sitter_scopes( } fn vsplit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1411,7 +1411,7 @@ fn vsplit( } fn hsplit( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1434,7 +1434,7 @@ fn hsplit( } fn vsplit_new( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1448,7 +1448,7 @@ fn vsplit_new( } fn hsplit_new( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1462,7 +1462,7 @@ fn hsplit_new( } fn debug_eval( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1488,7 +1488,7 @@ fn debug_eval( } fn debug_start( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1505,7 +1505,7 @@ fn debug_start( } fn debug_remote( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1526,7 +1526,7 @@ fn debug_remote( } fn tutor( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1542,7 +1542,7 @@ fn tutor( } pub(super) fn goto_line_number( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1587,7 +1587,7 @@ pub(super) fn goto_line_number( // Fetch the current value of a config option and output as status. fn get_option( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1613,7 +1613,7 @@ fn get_option( /// Change config at runtime. Access nested values by dot syntax, for /// example to disable smart case search, use `:set search.smart-case false`. fn set_option( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1652,7 +1652,7 @@ fn set_option( /// syntax, for example to toggle smart case search, use `:toggle search.smart- /// case`. fn toggle_option( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1690,7 +1690,7 @@ fn toggle_option( /// Change the language of the current buffer at runtime. fn language( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1723,7 +1723,7 @@ fn language( Ok(()) } -fn sort(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn sort(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -1732,7 +1732,7 @@ fn sort(cx: &mut compositor::CompositorContext, args: &[Cow], event: Prompt } fn sort_reverse( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1744,7 +1744,7 @@ fn sort_reverse( } fn sort_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], reverse: bool, ) -> anyhow::Result<()> { @@ -1780,7 +1780,7 @@ fn sort_impl( } fn reflow( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1825,7 +1825,7 @@ fn reflow( } fn tree_sitter_subtree( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1868,7 +1868,7 @@ fn tree_sitter_subtree( } fn open_config( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1882,7 +1882,7 @@ fn open_config( } fn open_log( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1895,7 +1895,7 @@ fn open_log( } fn refresh_config( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1908,7 +1908,7 @@ fn refresh_config( } fn append_output( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1922,7 +1922,7 @@ fn append_output( } fn insert_output( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -1936,19 +1936,19 @@ fn insert_output( } fn pipe_to( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { pipe_impl(cx, args, event, &ShellBehavior::Ignore) } -fn pipe(cx: &mut compositor::CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { +fn pipe(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { pipe_impl(cx, args, event, &ShellBehavior::Replace) } fn pipe_impl( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, behavior: &ShellBehavior, @@ -1963,7 +1963,7 @@ fn pipe_impl( } fn run_shell_command( - cx: &mut compositor::CompositorContext, + cx: &mut CompositorContext, args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { @@ -2607,7 +2607,7 @@ pub(super) fn command_mode(cx: &mut CommandContext) { } } }, // completion - move |cx: &mut compositor::CompositorContext, input: &str, event: PromptEvent| { + move |cx: &mut CompositorContext, input: &str, event: PromptEvent| { let parts = input.split_whitespace().collect::>(); if parts.is_empty() { return; diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 46d6c98ffe26..9a1d2be2a4d1 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1185,7 +1185,7 @@ impl Component for EditorView { fn handle_event( &mut self, event: &Event, - context: &mut crate::compositor::CompositorContext, + context: &mut CompositorContext, ) -> EventResult { let mut cx = CommandContext { editor: context.editor, diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index b028b9c5d549..86f3dc534831 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -15,7 +15,7 @@ mod statusline; mod text; use crate::commands::CommandContext; -use crate::compositor::{Component, Compositor}; +use crate::compositor::{Component, Compositor, CompositorContext}; use crate::filter_picker_entry; use crate::job::{self, Callback}; pub use completion::Completion; @@ -39,7 +39,7 @@ pub fn prompt( prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, - callback_fn: impl FnMut(&mut crate::compositor::CompositorContext, &str, PromptEvent) + 'static, + callback_fn: impl FnMut(&mut CompositorContext, &str, PromptEvent) + 'static, ) { let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn); // Calculate the initial completion @@ -53,7 +53,7 @@ pub fn prompt_with_input( input: String, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, - callback_fn: impl FnMut(&mut crate::compositor::CompositorContext, &str, PromptEvent) + 'static, + callback_fn: impl FnMut(&mut CompositorContext, &str, PromptEvent) + 'static, ) { let prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn) .with_line(input, cx.editor); @@ -77,7 +77,7 @@ pub fn regex_prompt( prompt, history_register, completion_fn, - move |cx: &mut crate::compositor::CompositorContext, input: &str, event: PromptEvent| { + move |cx: &mut CompositorContext, input: &str, event: PromptEvent| { match event { PromptEvent::Abort => { let (view, doc) = current!(cx.editor); From 42c1d81e9249cd9481d74b8093949aa184b1d449 Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sun, 19 Feb 2023 21:25:24 +0100 Subject: [PATCH 5/5] cargo fmt --- helix-term/src/application.rs | 2 +- helix-term/src/commands/typed.rs | 60 ++++++-------------------------- helix-term/src/ui/completion.rs | 5 ++- helix-term/src/ui/editor.rs | 14 ++------ 4 files changed, 18 insertions(+), 63 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 41ffefcbdda3..4f9a0130a817 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -21,7 +21,7 @@ use tui::backend::Backend; use crate::{ args::Args, commands::apply_workspace_edit, - compositor::{Compositor, Event, CompositorContext}, + compositor::{Compositor, CompositorContext, Event}, config::Config, job::Jobs, keymap::Keymaps, diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index d7b0e407a38f..005c6d1cc18b 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -316,11 +316,7 @@ fn write_impl( Ok(()) } -fn write( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn write(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -507,11 +503,7 @@ fn earlier( Ok(()) } -fn later( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn later(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -730,11 +722,7 @@ fn force_quit_all( quit_all_impl(cx, true) } -fn cquit( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn cquit(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -766,11 +754,7 @@ fn force_cquit( quit_all_impl(cx, true) } -fn theme( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn theme(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { let true_color = cx.editor.config.load().true_color || crate::true_color(); match event { PromptEvent::Abort => { @@ -1232,11 +1216,7 @@ fn reload_all( } /// Update the [`Document`] if it has been modified. -fn update( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn update(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -1387,11 +1367,7 @@ fn tree_sitter_scopes( Ok(()) } -fn vsplit( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn vsplit(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -1410,11 +1386,7 @@ fn vsplit( Ok(()) } -fn hsplit( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn hsplit(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -1525,11 +1497,7 @@ fn debug_remote( dap_start_impl(cx, name.as_deref(), address, Some(args)) } -fn tutor( - cx: &mut CompositorContext, - _args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn tutor(cx: &mut CompositorContext, _args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } @@ -1743,11 +1711,7 @@ fn sort_reverse( sort_impl(cx, args, true) } -fn sort_impl( - cx: &mut CompositorContext, - _args: &[Cow], - reverse: bool, -) -> anyhow::Result<()> { +fn sort_impl(cx: &mut CompositorContext, _args: &[Cow], reverse: bool) -> anyhow::Result<()> { let scrolloff = cx.editor.config().scrolloff; let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -1779,11 +1743,7 @@ fn sort_impl( Ok(()) } -fn reflow( - cx: &mut CompositorContext, - args: &[Cow], - event: PromptEvent, -) -> anyhow::Result<()> { +fn reflow(cx: &mut CompositorContext, args: &[Cow], event: PromptEvent) -> anyhow::Result<()> { if event != PromptEvent::Validate { return Ok(()); } diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 0912afd098c6..fc361d32a319 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -1,4 +1,7 @@ -use crate::{compositor::{Component, CompositorContext, Event, EventResult}, commands::CommandContext}; +use crate::{ + commands::CommandContext, + compositor::{Component, CompositorContext, Event, EventResult}, +}; use helix_view::{ editor::CompleteAction, theme::{Modifier, Style}, diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 9a1d2be2a4d1..82fcbe6de7dd 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1,5 +1,5 @@ use crate::{ - commands::{self, OnKeyCallback, CommandContext}, + commands::{self, CommandContext, OnKeyCallback}, compositor::{Component, CompositorContext, Event, EventResult}, job::{self, Callback}, key, @@ -997,11 +997,7 @@ impl EditorView { } impl EditorView { - fn handle_mouse_event( - &mut self, - event: &MouseEvent, - cxt: &mut CommandContext, - ) -> EventResult { + fn handle_mouse_event(&mut self, event: &MouseEvent, cxt: &mut CommandContext) -> EventResult { let config = cxt.editor.config(); let MouseEvent { kind, @@ -1182,11 +1178,7 @@ impl EditorView { } impl Component for EditorView { - fn handle_event( - &mut self, - event: &Event, - context: &mut CompositorContext, - ) -> EventResult { + fn handle_event(&mut self, event: &Event, context: &mut CompositorContext) -> EventResult { let mut cx = CommandContext { editor: context.editor, count: None,