From 7fbd7b48e58e262d2569f251a9da2bdf3fd9363c Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 27 Nov 2022 20:45:35 +0900 Subject: [PATCH] revset: highlight whole function expression on substitution failed The error may be caused by arguments passed in to the alias function. --- lib/src/revset.rs | 11 +++++++---- tests/test_revset_output.rs | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index cc2dfe960..3da2c7572 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -694,7 +694,7 @@ fn parse_expression_rule( .op(Op::postfix(Rule::parents_op) | Op::postfix(Rule::children_op)) }); PRATT - .map_primary(|primary| parse_primary_rule(primary.into_inner(), state)) + .map_primary(|primary| parse_primary_rule(primary, state)) .map_prefix(|op, rhs| match op.as_rule() { Rule::dag_range_pre_op | Rule::range_pre_op => Ok(rhs?.ancestors()), r => panic!("unexpected prefix operator rule {r:?}"), @@ -718,15 +718,17 @@ fn parse_expression_rule( } fn parse_primary_rule( - mut pairs: Pairs, + pair: Pair, state: ParseState, ) -> Result, RevsetParseError> { + let span = pair.as_span(); + let mut pairs = pair.into_inner(); let first = pairs.next().unwrap(); match first.as_rule() { Rule::expression => parse_expression_rule(first.into_inner(), state), Rule::function_name => { let arguments_pair = pairs.next().unwrap(); - parse_function_expression(first, arguments_pair, state) + parse_function_expression(first, arguments_pair, state, span) } Rule::symbol => parse_symbol_rule(first.into_inner(), state), _ => { @@ -775,6 +777,7 @@ fn parse_function_expression( name_pair: Pair, arguments_pair: Pair, state: ParseState, + primary_span: pest::Span<'_>, ) -> Result, RevsetParseError> { let name = name_pair.as_str(); if let Some((id, params, defn)) = state.aliases_map.get_function(name) { @@ -787,7 +790,7 @@ fn parse_function_expression( .collect::, RevsetParseError>>()?; if params.len() == args.len() { let locals = params.iter().map(|s| s.as_str()).zip(args).collect(); - state.with_alias_expanding(id, &locals, name_pair.as_span(), |state| { + state.with_alias_expanding(id, &locals, primary_span, |state| { parse_program(defn, state) }) } else { diff --git a/tests/test_revset_output.rs b/tests/test_revset_output.rs index fd7baff67..ce881cce9 100644 --- a/tests/test_revset_output.rs +++ b/tests/test_revset_output.rs @@ -182,7 +182,7 @@ fn test_alias() { Error: Failed to parse revset: --> 1:1 | 1 | my_author(none()) - | ^-------^ + | ^---------------^ | = Alias "my_author()" cannot be expanded --> 1:8 @@ -210,7 +210,7 @@ fn test_alias() { --> 1:1 | 1 | recurse2() - | ^------^ + | ^--------^ | = Alias "recurse2()" cannot be expanded --> 1:1