diff --git a/cli/src/template_parser.rs b/cli/src/template_parser.rs index 3bb2bb511..ac8ae5cc5 100644 --- a/cli/src/template_parser.rs +++ b/cli/src/template_parser.rs @@ -220,7 +220,7 @@ impl AliasExpandError for TemplateParseError { fn within_alias_expansion(self, id: AliasId<'_>, span: pest::Span<'_>) -> Self { let kind = match id { - AliasId::Symbol(_) | AliasId::Function(_) => { + AliasId::Symbol(_) | AliasId::Function(..) => { TemplateParseErrorKind::BadAliasExpansion(id.to_string()) } AliasId::Parameter(_) => TemplateParseErrorKind::BadParameterExpansion(id.to_string()), @@ -1035,7 +1035,7 @@ mod tests { assert_eq!(defn, r#""is symbol""#); let (id, params, defn) = aliases_map.get_function("func").unwrap(); - assert_eq!(id, AliasId::Function("func")); + assert_eq!(id, AliasId::Function("func", &["a".to_owned()])); assert_eq!(params, ["a"]); assert_eq!(defn, r#""is function""#); @@ -1219,7 +1219,7 @@ mod tests { .parse("F(a)") .unwrap_err() .kind, - TemplateParseErrorKind::BadAliasExpansion("F()".to_owned()), + TemplateParseErrorKind::BadAliasExpansion("F(x)".to_owned()), ); } } diff --git a/cli/tests/test_revset_output.rs b/cli/tests/test_revset_output.rs index 85556ec61..df723efbb 100644 --- a/cli/tests/test_revset_output.rs +++ b/cli/tests/test_revset_output.rs @@ -372,14 +372,14 @@ fn test_alias() { let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "my_author(none())"]); insta::assert_snapshot!(stderr, @r###" - Error: Failed to parse revset: Alias "my_author()" cannot be expanded + Error: Failed to parse revset: Alias "my_author(x)" cannot be expanded Caused by: 1: --> 1:1 | 1 | my_author(none()) | ^---------------^ | - = Alias "my_author()" cannot be expanded + = Alias "my_author(x)" cannot be expanded 2: --> 1:8 | 1 | author(x) diff --git a/cli/tests/test_templater.rs b/cli/tests/test_templater.rs index 5f086f22a..29255c750 100644 --- a/cli/tests/test_templater.rs +++ b/cli/tests/test_templater.rs @@ -84,14 +84,14 @@ fn test_templater_parse_error() { Hint: Did you mean "s", "self"? "###); insta::assert_snapshot!(render_err(r#"format_id(commit_id)"#), @r###" - Error: Failed to parse template: Alias "format_id()" cannot be expanded + Error: Failed to parse template: Alias "format_id(id)" cannot be expanded Caused by: 1: --> 1:1 | 1 | format_id(commit_id) | ^------------------^ | - = Alias "format_id()" cannot be expanded + = Alias "format_id(id)" cannot be expanded 2: --> 1:4 | 1 | id.sort() @@ -189,14 +189,14 @@ fn test_templater_alias() { "###); insta::assert_snapshot!(render_err(r#"identity(identity(commit_id.short("")))"#), @r###" - Error: Failed to parse template: Alias "identity()" cannot be expanded + Error: Failed to parse template: Alias "identity(x)" cannot be expanded Caused by: 1: --> 1:1 | 1 | identity(identity(commit_id.short(""))) | ^-------------------------------------^ | - = Alias "identity()" cannot be expanded + = Alias "identity(x)" cannot be expanded 2: --> 1:1 | 1 | x @@ -208,7 +208,7 @@ fn test_templater_alias() { 1 | identity(identity(commit_id.short(""))) | ^---------------------------^ | - = Alias "identity()" cannot be expanded + = Alias "identity(x)" cannot be expanded 4: --> 1:1 | 1 | x @@ -272,14 +272,14 @@ fn test_templater_alias() { "###); insta::assert_snapshot!(render_err(r#"coalesce(label("x", "not boolean"), "")"#), @r###" - Error: Failed to parse template: Alias "coalesce()" cannot be expanded + Error: Failed to parse template: Alias "coalesce(x, y)" cannot be expanded Caused by: 1: --> 1:1 | 1 | coalesce(label("x", "not boolean"), "") | ^-------------------------------------^ | - = Alias "coalesce()" cannot be expanded + = Alias "coalesce(x, y)" cannot be expanded 2: --> 1:4 | 1 | if(x, x, y) diff --git a/lib/src/dsl_util.rs b/lib/src/dsl_util.rs index 30144ae8e..d70799e4f 100644 --- a/lib/src/dsl_util.rs +++ b/lib/src/dsl_util.rs @@ -405,7 +405,13 @@ impl

AliasesMap

{ pub fn get_function(&self, name: &str) -> Option<(AliasId<'_>, &[String], &str)> { self.function_aliases .get_key_value(name) - .map(|(name, (params, defn))| (AliasId::Function(name), params.as_ref(), defn.as_ref())) + .map(|(name, (params, defn))| { + ( + AliasId::Function(name, params), + params.as_ref(), + defn.as_ref(), + ) + }) } } @@ -414,8 +420,8 @@ impl

AliasesMap

{ pub enum AliasId<'a> { /// Symbol name. Symbol(&'a str), - /// Function name. - Function(&'a str), + /// Function name and parameter names. + Function(&'a str, &'a [String]), /// Function parameter name. Parameter(&'a str), } @@ -424,7 +430,9 @@ impl fmt::Display for AliasId<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { AliasId::Symbol(name) => write!(f, "{name}"), - AliasId::Function(name) => write!(f, "{name}()"), + AliasId::Function(name, params) => { + write!(f, "{name}({params})", params = params.join(", ")) + } AliasId::Parameter(name) => write!(f, "{name}"), } } diff --git a/lib/src/revset_parser.rs b/lib/src/revset_parser.rs index d8c439819..d9aecf20d 100644 --- a/lib/src/revset_parser.rs +++ b/lib/src/revset_parser.rs @@ -233,7 +233,7 @@ impl AliasExpandError for RevsetParseError { fn within_alias_expansion(self, id: AliasId<'_>, span: pest::Span<'_>) -> Self { let kind = match id { - AliasId::Symbol(_) | AliasId::Function(_) => { + AliasId::Symbol(_) | AliasId::Function(..) => { RevsetParseErrorKind::BadAliasExpansion(id.to_string()) } AliasId::Parameter(_) => RevsetParseErrorKind::BadParameterExpansion(id.to_string()), @@ -1632,7 +1632,7 @@ mod tests { .parse("F(a)") .unwrap_err() .kind, - RevsetParseErrorKind::BadAliasExpansion("F()".to_owned()) + RevsetParseErrorKind::BadAliasExpansion("F(x)".to_owned()) ); } }