Skip to content

Commit

Permalink
abbr: expand command abbrs after decorators (#10396)
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
faho committed Mar 27, 2024
1 parent 326d986 commit 217b009
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/reader.rs
Expand Up @@ -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,
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/abbrs.rs
Expand Up @@ -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");
Expand Down

0 comments on commit 217b009

Please sign in to comment.