diff --git a/src/eval.rs b/src/eval.rs index adc4795054..a3cfe54e13 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -216,7 +216,7 @@ pub fn eval_expression( Ok(Value::List(output)) } Expr::Table(_, _) => Err(ShellError::Unsupported(expr.span)), - Expr::Keyword(_, expr) => eval_expression(state, stack, expr), + Expr::Keyword(_, _, expr) => eval_expression(state, stack, expr), Expr::String(s) => Ok(Value::String { val: s.clone(), span: expr.span, diff --git a/src/flatten.rs b/src/flatten.rs index 66e8f29688..e06e542044 100644 --- a/src/flatten.rs +++ b/src/flatten.rs @@ -43,9 +43,20 @@ impl<'a> ParserWorkingSet<'a> { Expr::Block(block_id) => self.flatten_block(self.get_block(*block_id)), Expr::Call(call) => { let mut output = vec![(call.head, FlatShape::InternalCall)]; + let mut last_span = call.head.end; for positional in &call.positional { + last_span = positional.span.end; output.extend(self.flatten_expression(positional)); } + if last_span < expr.span.end { + output.push(( + Span { + start: last_span, + end: expr.span.end, + }, + FlatShape::InternalCall, + )); + } output } Expr::ExternalCall(..) => { @@ -68,7 +79,11 @@ impl<'a> ParserWorkingSet<'a> { } output } - Expr::Keyword(_, expr) => self.flatten_expression(expr), + Expr::Keyword(_, span, expr) => { + let mut output = vec![(*span, FlatShape::Operator)]; + output.extend(self.flatten_expression(expr)); + output + } Expr::Operator(_) => { vec![(expr.span, FlatShape::Operator)] } diff --git a/src/parser.rs b/src/parser.rs index e8cf87db99..4abb426713 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -171,7 +171,7 @@ pub enum Expr { Block(BlockId), List(Vec), Table(Vec, Vec>), - Keyword(Vec, Box), + Keyword(Vec, Span, Box), String(String), // FIXME: improve this in the future? Signature(Box), Garbage, @@ -241,7 +241,7 @@ impl Expression { pub fn as_keyword(&self) -> Option<&Expression> { match &self.expr { - Expr::Keyword(_, expr) => Some(expr), + Expr::Keyword(_, _, expr) => Some(expr), _ => None, } } @@ -646,6 +646,7 @@ impl<'a> ParserWorkingSet<'a> { Expression { expr: Expr::Keyword( keyword.clone(), + spans[*spans_idx - 1], Box::new(Expression::garbage(arg_span)), ), span: arg_span, @@ -660,7 +661,7 @@ impl<'a> ParserWorkingSet<'a> { ( Expression { - expr: Expr::Keyword(keyword.clone(), Box::new(expr)), + expr: Expr::Keyword(keyword.clone(), spans[*spans_idx - 1], Box::new(expr)), span: arg_span, ty, },