Fix it expansion and add collect (#2065)

This commit is contained in:
Jonathan Turner
2020-06-27 17:38:19 +12:00
committed by GitHub
parent 05781607f4
commit 4e2a4236f8
7 changed files with 133 additions and 34 deletions

View File

@ -44,6 +44,14 @@ impl InternalCommand {
),
}
}
pub fn expand_it_usage(&mut self) {
if let Some(positionals) = &mut self.args.positional {
for arg in positionals {
arg.expand_it_usage();
}
}
}
}
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
@ -109,34 +117,8 @@ impl ClassifiedCommand {
pub fn expand_it_usage(&mut self) {
match self {
ClassifiedCommand::Internal(command) => {
if let Some(positionals) = &mut command.args.positional {
for arg in positionals {
if let SpannedExpression {
expr: Expression::Block(block),
..
} = arg
{
block.expand_it_usage();
}
}
}
}
ClassifiedCommand::Expr(expr) => {
if let SpannedExpression {
expr: Expression::Block(ref block),
span,
} = **expr
{
let mut block = block.clone();
block.expand_it_usage();
*expr = Box::new(SpannedExpression {
expr: Expression::Block(block),
span,
});
}
}
ClassifiedCommand::Internal(command) => command.expand_it_usage(),
ClassifiedCommand::Expr(expr) => expr.expand_it_usage(),
_ => {}
}
}
@ -588,6 +570,44 @@ impl SpannedExpression {
_ => false,
}
}
pub fn expand_it_usage(&mut self) {
match self {
SpannedExpression {
expr: Expression::Block(block),
..
} => {
block.expand_it_usage();
}
SpannedExpression {
expr: Expression::Invocation(block),
..
} => {
block.expand_it_usage();
}
SpannedExpression {
expr: Expression::List(list),
..
} => {
for item in list.iter_mut() {
item.expand_it_usage();
}
}
SpannedExpression {
expr: Expression::Path(path),
..
} => {
if let SpannedExpression {
expr: Expression::Invocation(block),
..
} = &mut path.head
{
block.expand_it_usage();
}
}
_ => {}
}
}
}
impl std::ops::Deref for SpannedExpression {