From 217b009e18f2cb5d854e3777b73052d1bf08ce05 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 27 Mar 2024 17:17:55 +0100 Subject: [PATCH] abbr: expand command abbrs after decorators (#10396) Currently, we expand command-abbrs (those with `--position command`) after `if`, but not after `command` or `builtin` or `time`: ```fish abbr --add gc "git checkout" ``` will expand as `if gc` but not as `command gc`. This was explicitly tested, but I have no idea why it shouldn't be? --- src/reader.rs | 6 +++--- src/tests/abbrs.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 30293f10c..6caa42e74 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -4340,7 +4340,7 @@ fn expand_replacer( )) } -// Extract all the token ranges in \p str, along with whether they are an undecorated command. +// Extract all the token ranges in \p str, along with whether they are a command. // Tokens containing command substitutions are skipped; this ensures tokens are non-overlapping. struct PositionedToken { range: SourceRange, @@ -4353,12 +4353,12 @@ fn extract_tokens(s: &wstr) -> Vec { | ParseTreeFlags::LEAVE_UNTERMINATED; let ast = Ast::parse(s, ast_flags, None); - // Helper to check if a node is the command portion of an undecorated statement. + // Helper to check if a node is the command portion of a decorated statement. let is_command = |node: &dyn ast::Node| { let mut cursor = Some(node); while let Some(cur) = cursor { if let Some(stmt) = cur.as_decorated_statement() { - if stmt.opt_decoration.is_none() && node.pointer_eq(&stmt.command) { + if node.pointer_eq(&stmt.command) { return true; } } diff --git a/src/tests/abbrs.rs b/src/tests/abbrs.rs index 9528e0bd9..485d89955 100644 --- a/src/tests/abbrs.rs +++ b/src/tests/abbrs.rs @@ -131,8 +131,8 @@ macro_rules! validate { // Others should not be. validate!("of gc", None); - // Others should not be. - validate!("command gc", None); + // Other decorations generally should be. + validate!("command gc", None, "command git checkout"); // yin/yang expands everywhere. validate!("command yin", None, "command yang");