From 68d1207d530a93d38a8a36d9e532543f5fc44246 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 14 Jan 2024 12:31:32 +0100 Subject: [PATCH] Rename flag that fails expansions with command substitutions SKIP_CMDSUBST does not pass through command substitutions, unlike SKIP_VARIABLES and SKIP_WILDCARDS. --- src/complete.rs | 12 ++++++------ src/expand.rs | 16 ++++++---------- src/highlight.rs | 6 +++--- src/history.rs | 4 ++-- src/parse_execution.rs | 2 +- src/parse_util.rs | 2 +- src/reader.rs | 2 +- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/complete.rs b/src/complete.rs index 80b1b199c..28d4654cd 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -903,7 +903,7 @@ impl<'ctx> Completer<'ctx> { &mut tmp, self.expand_flags() | extra_expand_flags - | ExpandFlags::SKIP_CMDSUBST + | ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, self.ctx, None, @@ -930,7 +930,7 @@ impl<'ctx> Completer<'ctx> { fn expand_flags(&self) -> ExpandFlags { let mut result = ExpandFlags::empty(); - result.set(ExpandFlags::SKIP_CMDSUBST, self.flags.autosuggestion); + result.set(ExpandFlags::FAIL_ON_CMDSUBST, self.flags.autosuggestion); result.set(ExpandFlags::FUZZY_MATCH, self.flags.fuzzy_match); result.set(ExpandFlags::GEN_DESCRIPTIONS, self.flags.descriptions); result @@ -1164,7 +1164,7 @@ impl<'ctx> Completer<'ctx> { }; let eflags = if is_autosuggest { - ExpandFlags::SKIP_CMDSUBST + ExpandFlags::FAIL_ON_CMDSUBST } else { ExpandFlags::empty() }; @@ -1502,7 +1502,7 @@ impl<'ctx> Completer<'ctx> { return; } let mut flags = self.expand_flags() - | ExpandFlags::SKIP_CMDSUBST + | ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::FOR_COMPLETIONS | ExpandFlags::PRESERVE_HOME_TILDES; if !do_file { @@ -1817,7 +1817,7 @@ impl<'ctx> Completer<'ctx> { // VAR=(launch_missiles) cmd // should not launch missiles. // Note we also do NOT send --on-variable events. - let expand_flags = ExpandFlags::SKIP_CMDSUBST; + let expand_flags = ExpandFlags::FAIL_ON_CMDSUBST; let block = parser.push_block(Block::variable_assignment_block()); for var_assign in var_assignments { let equals_pos = variable_assignment_equals_pos(var_assign) @@ -2185,7 +2185,7 @@ fn expand_command_token(ctx: &OperationContext<'_>, cmd_tok: &mut WString) -> bo // Also we could expand wildcards. expand_one( cmd_tok, - ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, + ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, ctx, None, ) diff --git a/src/expand.rs b/src/expand.rs index acb4d97c9..2305fdbb3 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -32,8 +32,8 @@ bitflags! { /// Set of flags controlling expansions. #[derive(Copy, Clone, Default)] pub struct ExpandFlags : u16 { - /// Skip command substitutions. - const SKIP_CMDSUBST = 1 << 0; + /// Fail expansion if there is a command substitution. + const FAIL_ON_CMDSUBST = 1 << 0; /// Skip variable expansion. const SKIP_VARIABLES = 1 << 1; /// Skip wildcard expansion. @@ -132,8 +132,6 @@ pub const PROCESS_EXPAND_SELF_STR: &wstr = L!("%self"); /// /// \param input The parameter to expand /// \param output The list to which the result will be appended. -/// \param flags Specifies if any expansion pass should be skipped. Legal values are any combination -/// of skip_cmdsubst skip_variables and skip_wildcards /// \param ctx The parser, variables, and cancellation checker for this operation. The parser may /// be null. \param errors Resulting errors, or nullptr to ignore /// @@ -170,8 +168,6 @@ pub fn expand_to_receiver( /// string. This is used for expanding command names. /// /// \param inout_str The parameter to expand in-place -/// \param flags Specifies if any expansion pass should be skipped. Legal values are any combination -/// of skip_cmdsubst skip_variables and skip_wildcards /// \param ctx The parser, variables, and cancellation checker for this operation. The parser may be /// null. /// \param errors Resulting errors, or nullptr to ignore @@ -222,7 +218,7 @@ pub fn expand_to_command_and_args( return ExpandResult::ok(); } - let mut eflags = ExpandFlags::SKIP_CMDSUBST; + let mut eflags = ExpandFlags::FAIL_ON_CMDSUBST; if skip_wildcards { eflags |= ExpandFlags::SKIP_WILDCARDS; } @@ -851,7 +847,7 @@ fn expand_braces( } // Note: this code looks very fishy, apparently it has never worked. - return expand_braces(synth, ExpandFlags::SKIP_CMDSUBST, out, errors); + return expand_braces(synth, ExpandFlags::FAIL_ON_CMDSUBST, out, errors); } } @@ -1239,7 +1235,7 @@ impl<'a, 'b, 'c> Expander<'a, 'b, 'c> { mut errors: Option<&'a mut ParseErrorList>, ) -> ExpandResult { assert!( - flags.contains(ExpandFlags::SKIP_CMDSUBST) || ctx.has_parser(), + flags.contains(ExpandFlags::FAIL_ON_CMDSUBST) || ctx.has_parser(), "Must have a parser if not skipping command substitutions" ); // Early out. If we're not completing, and there's no magic in the input, we're done. @@ -1313,7 +1309,7 @@ impl<'a, 'b, 'c> Expander<'a, 'b, 'c> { } fn stage_cmdsubst(&mut self, input: WString, out: &mut CompletionReceiver) -> ExpandResult { - if self.flags.contains(ExpandFlags::SKIP_CMDSUBST) { + if self.flags.contains(ExpandFlags::FAIL_ON_CMDSUBST) { let mut cursor = 0; let mut start = 0; let mut end = 0; diff --git a/src/highlight.rs b/src/highlight.rs index 75a4d6669..f3314b111 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -336,7 +336,7 @@ pub fn autosuggest_validate_from_history( // We handle cd specially. if parsed_command == "cd" && !cd_dir.is_empty() { - if expand_one(&mut cd_dir, ExpandFlags::SKIP_CMDSUBST, ctx, None) { + if expand_one(&mut cd_dir, ExpandFlags::FAIL_ON_CMDSUBST, ctx, None) { if string_prefixes_string(&cd_dir, L!("--help")) || string_prefixes_string(&cd_dir, L!("-h")) { @@ -1149,7 +1149,7 @@ impl<'s> Highlighter<'s> { if cmd_is_cd { // Mark this as an error if it's not 'help' and not a valid cd path. let mut param = arg.source(self.buff).to_owned(); - if expand_one(&mut param, ExpandFlags::SKIP_CMDSUBST, self.ctx, None) { + if expand_one(&mut param, ExpandFlags::FAIL_ON_CMDSUBST, self.ctx, None) { let is_help = string_prefixes_string(¶m, L!("--help")) || string_prefixes_string(¶m, L!("-h")); if !is_help { @@ -1221,7 +1221,7 @@ impl<'s> Highlighter<'s> { target_is_valid = true; } else if contains_pending_variable(&self.pending_variables, &target) { target_is_valid = true; - } else if !expand_one(&mut target, ExpandFlags::SKIP_CMDSUBST, self.ctx, None) { + } else if !expand_one(&mut target, ExpandFlags::FAIL_ON_CMDSUBST, self.ctx, None) { // Could not be expanded. target_is_valid = false; } else { diff --git a/src/history.rs b/src/history.rs index cf2470bf9..bf26cd2f5 100644 --- a/src/history.rs +++ b/src/history.rs @@ -1976,7 +1976,7 @@ pub fn expand_and_detect_paths>( let mut expanded_path = path.clone(); if expand_one( &mut expanded_path, - ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, + ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, &ctx, None, ) && path_is_valid(&expanded_path, &working_directory) @@ -2004,7 +2004,7 @@ pub fn all_paths_are_valid>( } if !expand_one( &mut path, - ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, + ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_WILDCARDS, ctx, None, ) { diff --git a/src/parse_execution.rs b/src/parse_execution.rs index 9f9d359d8..d4f963251 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -475,7 +475,7 @@ impl<'a> ParseExecutionContext { let forbidden = !cmd.is_empty() && expand_one( &mut cmd, - ExpandFlags::SKIP_CMDSUBST | ExpandFlags::SKIP_VARIABLES, + ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_VARIABLES, ctx, None, ) diff --git a/src/parse_util.rs b/src/parse_util.rs index f03db2c6a..4e93a1c54 100644 --- a/src/parse_util.rs +++ b/src/parse_util.rs @@ -1638,7 +1638,7 @@ fn detect_errors_in_decorated_statement( let mut command = unexp_command.to_owned(); if expand_one( &mut command, - ExpandFlags::SKIP_CMDSUBST, + ExpandFlags::FAIL_ON_CMDSUBST, &OperationContext::empty(), match parse_errors { Some(pe) => Some(pe), diff --git a/src/reader.rs b/src/reader.rs index b1bc77e6c..fc3993cca 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -4811,7 +4811,7 @@ fn try_expand_wildcard( // We do wildcards only. - let flags = ExpandFlags::SKIP_CMDSUBST + let flags = ExpandFlags::FAIL_ON_CMDSUBST | ExpandFlags::SKIP_VARIABLES | ExpandFlags::PRESERVE_HOME_TILDES; let mut expanded = CompletionList::new();