Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands/typed.rs')
| -rw-r--r-- | helix-term/src/commands/typed.rs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 263d337a..d26b4705 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -29,15 +29,6 @@ pub struct TypableCommand { pub signature: Signature, } -impl TypableCommand { - fn completer_for_argument_number(&self, n: usize) -> &Completer { - match self.completer.positional_args.get(n) { - Some(completer) => completer, - _ => &self.completer.var_args, - } - } -} - #[derive(Clone)] pub struct CommandCompleter { // Arguments with specific completion methods based on their position. @@ -68,6 +59,13 @@ impl CommandCompleter { var_args: completer, } } + + fn for_argument_number(&self, n: usize) -> &Completer { + match self.positional_args.get(n) { + Some(completer) => completer, + _ => &self.var_args, + } + } } fn quit(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyhow::Result<()> { @@ -2658,13 +2656,13 @@ const BUFFER_CLOSE_OTHERS_SIGNATURE: Signature = Signature { // but Signature does not yet allow for var args. /// This command handles all of its input as-is with no quoting or flags. -const SHELL_SIGNATURE: Signature = Signature { +pub const SHELL_SIGNATURE: Signature = Signature { positionals: (1, Some(2)), raw_after: Some(1), ..Signature::DEFAULT }; -const SHELL_COMPLETER: CommandCompleter = CommandCompleter::positional(&[ +pub const SHELL_COMPLETER: CommandCompleter = CommandCompleter::positional(&[ // Command name completers::program, // Shell argument(s) @@ -3831,14 +3829,15 @@ fn complete_command_line(editor: &Editor, input: &str) -> Vec<ui::prompt::Comple .get(command) .map_or_else(Vec::new, |cmd| { let args_offset = command.len() + 1; - complete_command_args(editor, cmd, rest, args_offset) + complete_command_args(editor, cmd.signature, &cmd.completer, rest, args_offset) }) } } -fn complete_command_args( +pub fn complete_command_args( editor: &Editor, - command: &TypableCommand, + signature: Signature, + completer: &CommandCompleter, input: &str, offset: usize, ) -> Vec<ui::prompt::Completion> { @@ -3850,7 +3849,7 @@ fn complete_command_args( let cursor = input.len(); let prefix = &input[..cursor]; let mut tokenizer = Tokenizer::new(prefix, false); - let mut args = Args::new(command.signature, false); + let mut args = Args::new(signature, false); let mut final_token = None; let mut is_last_token = true; @@ -3894,7 +3893,7 @@ fn complete_command_args( .len() .checked_sub(1) .expect("completion state to be positional"); - let completer = command.completer_for_argument_number(n); + let completer = completer.for_argument_number(n); completer(editor, &token.content) .into_iter() @@ -3903,7 +3902,7 @@ fn complete_command_args( } CompletionState::Flag(_) => fuzzy_match( token.content.trim_start_matches('-'), - command.signature.flags.iter().map(|flag| flag.name), + signature.flags.iter().map(|flag| flag.name), false, ) .into_iter() @@ -3928,7 +3927,7 @@ fn complete_command_args( .len() .checked_sub(1) .expect("completion state to be positional"); - command.completer_for_argument_number(n) + completer.for_argument_number(n) }); complete_expand(editor, &token, arg_completer, offset + token.content_start) } |