Fix syntax highlighting for not (#12815)

# Description
Fixes #12813 where a panic occurs when syntax highlighting `not`. Also
fixes #12814 where syntax highlighting for `not` no longer works.

# User-Facing Changes
Bug fix.
This commit is contained in:
Ian Manske 2024-05-09 23:09:44 +00:00 committed by GitHub
parent 7271ad7909
commit 1b2e680059
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1 @@
mod nu_highlight;

View File

@ -0,0 +1,7 @@
use nu_test_support::nu;
#[test]
fn nu_highlight_not_expr() {
let actual = nu!("'not false' | nu-highlight | ansi strip");
assert_eq!(actual.out, "not false");
}

View File

@ -0,0 +1,2 @@
mod commands;
mod completions;

View File

@ -180,12 +180,12 @@ fn flatten_expression_into(
flatten_expression_into(working_set, op, output); flatten_expression_into(working_set, op, output);
flatten_expression_into(working_set, rhs, output); flatten_expression_into(working_set, rhs, output);
} }
Expr::UnaryNot(expr) => { Expr::UnaryNot(not) => {
output.push(( output.push((
Span::new(expr.span.start, expr.span.start + 3), Span::new(expr.span.start, expr.span.start + 3),
FlatShape::Operator, FlatShape::Operator,
)); ));
flatten_expression_into(working_set, expr, output); flatten_expression_into(working_set, not, output);
} }
Expr::Closure(block_id) => { Expr::Closure(block_id) => {
let outer_span = expr.span; let outer_span = expr.span;