mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-22 05:29:10 +08:00
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:
parent
326d986186
commit
217b009e18
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user