cleanup some highlighting

This commit is contained in:
JT 2021-07-30 16:38:41 +12:00
parent 7cac5bb633
commit 184125a70a
3 changed files with 21 additions and 5 deletions

View file

@ -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,

View file

@ -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)]
}

View file

@ -171,7 +171,7 @@ pub enum Expr {
Block(BlockId),
List(Vec<Expression>),
Table(Vec<Expression>, Vec<Vec<Expression>>),
Keyword(Vec<u8>, Box<Expression>),
Keyword(Vec<u8>, Span, Box<Expression>),
String(String), // FIXME: improve this in the future?
Signature(Box<Signature>),
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,
},