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?
This commit is contained in:
Fabian Boehm 2024-03-27 17:17:55 +01:00 committed by GitHub
parent 326d986186
commit 217b009e18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -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<PositionedToken> {
| 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;
}
}

View File

@ -131,8 +131,8 @@ fn test_abbreviations() {
// 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");