From 780f9e547d43a8a8a60346ca2e5aa4ff2bd24d12 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 30 Apr 2025 13:56:50 +0900 Subject: [PATCH] templater: call property wrap_() functions directly, delete old forwarding fns This patch replaces single-char L type aliases with P, and renames the L aliases where that makes sense. Many of the P aliases will be removed later by introducing generic wrap() trait. --- cli/examples/custom-commit-templater/main.rs | 12 +- .../custom-operation-templater/main.rs | 10 +- cli/src/cli_util.rs | 16 +- cli/src/commands/bookmark/list.rs | 4 +- cli/src/commands/bookmark/track.rs | 4 +- cli/src/commands/config/list.rs | 26 +- cli/src/commands/evolog.rs | 6 +- cli/src/commands/file/annotate.rs | 4 +- cli/src/commands/file/list.rs | 4 +- cli/src/commands/log.rs | 6 +- cli/src/commands/operation/diff.rs | 9 +- cli/src/commands/operation/log.rs | 9 +- cli/src/commands/operation/show.rs | 9 +- cli/src/commands/tag.rs | 4 +- cli/src/commit_templater.rs | 295 +++++------------ cli/src/generic_templater.rs | 7 - cli/src/operation_templater.rs | 35 +- cli/src/template_builder.rs | 311 ++++++++---------- 18 files changed, 306 insertions(+), 465 deletions(-) diff --git a/cli/examples/custom-commit-templater/main.rs b/cli/examples/custom-commit-templater/main.rs index bf1c0c342..200ea2389 100644 --- a/cli/examples/custom-commit-templater/main.rs +++ b/cli/examples/custom-commit-templater/main.rs @@ -18,9 +18,9 @@ use std::rc::Rc; use itertools::Itertools as _; use jj_cli::cli_util::CliRunner; use jj_cli::commit_templater::CommitTemplateBuildFnTable; -use jj_cli::commit_templater::CommitTemplateLanguage; use jj_cli::commit_templater::CommitTemplateLanguageExtension; -use jj_cli::template_builder::TemplateLanguage as _; +use jj_cli::commit_templater::CommitTemplatePropertyKind; +use jj_cli::template_builder::CoreTemplatePropertyVar as _; use jj_cli::template_parser; use jj_cli::template_parser::TemplateParseError; use jj_cli::templater::TemplatePropertyExt as _; @@ -121,7 +121,7 @@ impl SymbolResolverExtension for TheDigitest { impl CommitTemplateLanguageExtension for HexCounter { fn build_fn_table<'repo>(&self) -> CommitTemplateBuildFnTable<'repo> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; let mut table = CommitTemplateBuildFnTable::empty(); table.commit_methods.insert( "has_most_digits", @@ -133,7 +133,7 @@ impl CommitTemplateLanguageExtension for HexCounter { .count(language.repo()); let out_property = property.map(move |commit| num_digits_in_id(commit.id()) == most_digits); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); table.commit_methods.insert( @@ -141,7 +141,7 @@ impl CommitTemplateLanguageExtension for HexCounter { |_language, _diagnostics, _build_context, property, call| { call.expect_no_arguments()?; let out_property = property.map(|commit| num_digits_in_id(commit.id())); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); table.commit_methods.insert( @@ -161,7 +161,7 @@ impl CommitTemplateLanguageExtension for HexCounter { })?; let out_property = property.map(move |commit| num_char_in_id(commit, char_arg)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); diff --git a/cli/examples/custom-operation-templater/main.rs b/cli/examples/custom-operation-templater/main.rs index 0608568c0..f5bd1b112 100644 --- a/cli/examples/custom-operation-templater/main.rs +++ b/cli/examples/custom-operation-templater/main.rs @@ -14,9 +14,9 @@ use jj_cli::cli_util::CliRunner; use jj_cli::operation_templater::OperationTemplateBuildFnTable; -use jj_cli::operation_templater::OperationTemplateLanguage; use jj_cli::operation_templater::OperationTemplateLanguageExtension; -use jj_cli::template_builder::TemplateLanguage as _; +use jj_cli::operation_templater::OperationTemplatePropertyKind; +use jj_cli::template_builder::CoreTemplatePropertyVar as _; use jj_cli::template_parser; use jj_cli::template_parser::TemplateParseError; use jj_cli::templater::TemplatePropertyExt as _; @@ -49,14 +49,14 @@ fn num_char_in_id(operation: Operation, ch_match: char) -> i64 { impl OperationTemplateLanguageExtension for HexCounter { fn build_fn_table(&self) -> OperationTemplateBuildFnTable { - type L = OperationTemplateLanguage; + type P = OperationTemplatePropertyKind; let mut table = OperationTemplateBuildFnTable::empty(); table.operation_methods.insert( "num_digits_in_id", |_language, _diagnostics, _build_context, property, call| { call.expect_no_arguments()?; let out_property = property.map(|operation| num_digits_in_id(operation.id())); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); table.operation_methods.insert( @@ -77,7 +77,7 @@ impl OperationTemplateLanguageExtension for HexCounter { let out_property = property.map(move |operation| num_char_in_id(operation, char_arg)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 6a2df6215..cc5613f3e 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -152,6 +152,7 @@ use crate::command_error::user_error_with_hint; use crate::command_error::CommandError; use crate::commit_templater::CommitTemplateLanguage; use crate::commit_templater::CommitTemplateLanguageExtension; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::config::config_from_environment; use crate::config::parse_config_args; @@ -171,6 +172,7 @@ use crate::merge_tools::MergeEditor; use crate::merge_tools::MergeToolConfigError; use crate::operation_templater::OperationTemplateLanguage; use crate::operation_templater::OperationTemplateLanguageExtension; +use crate::operation_templater::OperationTemplatePropertyKind; use crate::revset_util; use crate::revset_util::RevsetExpressionEvaluator; use crate::template_builder; @@ -1738,7 +1740,7 @@ to the current parents may contain changes from multiple commits. ui, &language, template_text, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, ) } @@ -1753,7 +1755,7 @@ to the current parents may contain changes from multiple commits. ui, &language, template_text, - OperationTemplateLanguage::wrap_operation, + OperationTemplatePropertyKind::wrap_operation, ) } @@ -1778,7 +1780,7 @@ to the current parents may contain changes from multiple commits. self.reparse_valid_template( &language, &self.commit_summary_template_text, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, ) } @@ -1788,7 +1790,7 @@ to the current parents may contain changes from multiple commits. self.reparse_valid_template( &language, &self.op_summary_template_text, - OperationTemplateLanguage::wrap_operation, + OperationTemplatePropertyKind::wrap_operation, ) .labeled("operation") } @@ -1798,7 +1800,7 @@ to the current parents may contain changes from multiple commits. self.reparse_valid_template( &language, SHORT_CHANGE_ID_TEMPLATE_TEXT, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, ) } @@ -2460,7 +2462,7 @@ impl WorkspaceCommandTransaction<'_> { self.helper.reparse_valid_template( &language, &self.helper.commit_summary_template_text, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, ) } @@ -2486,7 +2488,7 @@ impl WorkspaceCommandTransaction<'_> { ui, &language, template_text, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, ) } diff --git a/cli/src/commands/bookmark/list.rs b/cli/src/commands/bookmark/list.rs index 2a969d46f..bd998dc10 100644 --- a/cli/src/commands/bookmark/list.rs +++ b/cli/src/commands/bookmark/list.rs @@ -33,7 +33,7 @@ use crate::cli_util::CommandHelper; use crate::cli_util::RevisionArg; use crate::command_error::CommandError; use crate::commit_templater::CommitRef; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::ui::Ui; @@ -184,7 +184,7 @@ pub fn cmd_bookmark_list( ui, &language, &text, - CommitTemplateLanguage::wrap_commit_ref, + CommitTemplatePropertyKind::wrap_commit_ref, )? .labeled("bookmark_list") }; diff --git a/cli/src/commands/bookmark/track.rs b/cli/src/commands/bookmark/track.rs index beb9b683a..d0ba75d5e 100644 --- a/cli/src/commands/bookmark/track.rs +++ b/cli/src/commands/bookmark/track.rs @@ -22,7 +22,7 @@ use crate::cli_util::CommandHelper; use crate::cli_util::RemoteBookmarkNamePattern; use crate::command_error::CommandError; use crate::commit_templater::CommitRef; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::ui::Ui; @@ -97,7 +97,7 @@ pub fn cmd_bookmark_track( ui, &language, &text, - CommitTemplateLanguage::wrap_commit_ref, + CommitTemplatePropertyKind::wrap_commit_ref, )? .labeled("bookmark_list") }; diff --git a/cli/src/commands/config/list.rs b/cli/src/commands/config/list.rs index 99270712e..e37d8dde8 100644 --- a/cli/src/commands/config/list.rs +++ b/cli/src/commands/config/list.rs @@ -25,7 +25,9 @@ use crate::complete; use crate::config::resolved_config_values; use crate::config::AnnotatedValue; use crate::generic_templater::GenericTemplateLanguage; -use crate::template_builder::TemplateLanguage as _; +use crate::generic_templater::GenericTemplatePropertyKind; +use crate::template_builder::CoreTemplatePropertyVar as _; +use crate::template_builder::TemplateLanguage; use crate::templater::TemplatePropertyExt as _; use crate::ui::Ui; @@ -83,7 +85,7 @@ pub fn cmd_config_list( None => command.settings().get_string("templates.config_list")?, }; command - .parse_template(ui, &language, &text, GenericTemplateLanguage::wrap_self)? + .parse_template(ui, &language, &text, GenericTemplatePropertyKind::wrap_self)? .labeled("config_list") }; @@ -118,25 +120,25 @@ pub fn cmd_config_list( Ok(()) } +type ConfigTemplateLanguage = GenericTemplateLanguage<'static, AnnotatedValue>; + // AnnotatedValue will be cloned internally in the templater. If the cloning // cost matters, wrap it with Rc. -fn config_template_language( - settings: &UserSettings, -) -> GenericTemplateLanguage<'static, AnnotatedValue> { - type L = GenericTemplateLanguage<'static, AnnotatedValue>; - let mut language = L::new(settings); +fn config_template_language(settings: &UserSettings) -> ConfigTemplateLanguage { + type P = >::Property; + let mut language = ConfigTemplateLanguage::new(settings); language.add_keyword("name", |self_property| { let out_property = self_property.map(|annotated| annotated.name.to_string()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }); language.add_keyword("value", |self_property| { // .decorated("", "") to trim leading/trailing whitespace let out_property = self_property.map(|annotated| annotated.value.decorated("", "")); - Ok(L::wrap_config_value(out_property.into_dyn())) + Ok(P::wrap_config_value(out_property.into_dyn())) }); language.add_keyword("source", |self_property| { let out_property = self_property.map(|annotated| annotated.source.to_string()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }); language.add_keyword("path", |self_property| { let out_property = self_property.map(|annotated| { @@ -146,11 +148,11 @@ fn config_template_language( .as_ref() .map_or_else(String::new, |path| path.to_string_lossy().into_owned()) }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }); language.add_keyword("overridden", |self_property| { let out_property = self_property.map(|annotated| annotated.is_overridden); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }); language } diff --git a/cli/src/commands/evolog.rs b/cli/src/commands/evolog.rs index 74bb590b1..6c09d6ae1 100644 --- a/cli/src/commands/evolog.rs +++ b/cli/src/commands/evolog.rs @@ -29,7 +29,7 @@ use crate::cli_util::CommandHelper; use crate::cli_util::LogContentFormat; use crate::cli_util::RevisionArg; use crate::command_error::CommandError; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::diff_util::DiffFormatArgs; use crate::graphlog::get_graphlog; @@ -114,7 +114,7 @@ pub(crate) fn cmd_evolog( ui, &language, &template_string, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, )? .labeled("log"); node_template = workspace_command @@ -122,7 +122,7 @@ pub(crate) fn cmd_evolog( ui, &language, &get_node_template(graph_style, workspace_command.settings())?, - CommitTemplateLanguage::wrap_commit_opt, + CommitTemplatePropertyKind::wrap_commit_opt, )? .labeled("node"); } diff --git a/cli/src/commands/file/annotate.rs b/cli/src/commands/file/annotate.rs index 055118d70..43032e0ad 100644 --- a/cli/src/commands/file/annotate.rs +++ b/cli/src/commands/file/annotate.rs @@ -25,7 +25,7 @@ use crate::cli_util::RevisionArg; use crate::command_error::user_error; use crate::command_error::CommandError; use crate::commit_templater::AnnotationLine; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::templater::TemplateRenderer; use crate::ui::Ui; @@ -101,7 +101,7 @@ pub(crate) fn cmd_file_annotate( ui, &language, &template_text, - CommitTemplateLanguage::wrap_annotation_line, + CommitTemplatePropertyKind::wrap_annotation_line, )?; // TODO: Should we add an option to limit the domain to e.g. recent commits? diff --git a/cli/src/commands/file/list.rs b/cli/src/commands/file/list.rs index eb266e4af..26463970d 100644 --- a/cli/src/commands/file/list.rs +++ b/cli/src/commands/file/list.rs @@ -18,7 +18,7 @@ use tracing::instrument; use crate::cli_util::CommandHelper; use crate::cli_util::RevisionArg; use crate::command_error::CommandError; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::commit_templater::TreeEntry; use crate::complete; use crate::ui::Ui; @@ -77,7 +77,7 @@ pub(crate) fn cmd_file_list( ui, &language, &text, - CommitTemplateLanguage::wrap_tree_entry, + CommitTemplatePropertyKind::wrap_tree_entry, )? .labeled("file_list") }; diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index 800da6293..fe4df0e93 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -35,7 +35,7 @@ use crate::cli_util::CommandHelper; use crate::cli_util::LogContentFormat; use crate::cli_util::RevisionArg; use crate::command_error::CommandError; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::diff_util::DiffFormatArgs; use crate::graphlog::get_graphlog; @@ -176,7 +176,7 @@ pub(crate) fn cmd_log( ui, &language, &template_string, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, )? .labeled("log"); node_template = workspace_command @@ -184,7 +184,7 @@ pub(crate) fn cmd_log( ui, &language, &get_node_template(graph_style, settings)?, - CommitTemplateLanguage::wrap_commit_opt, + CommitTemplatePropertyKind::wrap_commit_opt, )? .labeled("node"); } diff --git a/cli/src/commands/operation/diff.rs b/cli/src/commands/operation/diff.rs index 3f671bc27..42ee242f6 100644 --- a/cli/src/commands/operation/diff.rs +++ b/cli/src/commands/operation/diff.rs @@ -40,7 +40,7 @@ use jj_lib::revset::RevsetIteratorExt as _; use crate::cli_util::CommandHelper; use crate::cli_util::LogContentFormat; use crate::command_error::CommandError; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::diff_util::diff_formats_for_log; use crate::diff_util::DiffFormatArgs; @@ -132,7 +132,12 @@ pub fn cmd_op_diff( let commit_summary_template = { let language = workspace_env.commit_template_language(merged_repo, &id_prefix_context); let text = settings.get_string("templates.commit_summary")?; - workspace_env.parse_template(ui, &language, &text, CommitTemplateLanguage::wrap_commit)? + workspace_env.parse_template( + ui, + &language, + &text, + CommitTemplatePropertyKind::wrap_commit, + )? }; let op_summary_template = workspace_command.operation_summary_template(); diff --git a/cli/src/commands/operation/log.rs b/cli/src/commands/operation/log.rs index 78fa35d04..676db35db 100644 --- a/cli/src/commands/operation/log.rs +++ b/cli/src/commands/operation/log.rs @@ -32,7 +32,7 @@ use crate::cli_util::CommandHelper; use crate::cli_util::LogContentFormat; use crate::cli_util::WorkspaceCommandEnvironment; use crate::command_error::CommandError; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::diff_util::diff_formats_for_log; use crate::diff_util::DiffFormatArgs; @@ -41,6 +41,7 @@ use crate::formatter::Formatter; use crate::graphlog::get_graphlog; use crate::graphlog::GraphStyle; use crate::operation_templater::OperationTemplateLanguage; +use crate::operation_templater::OperationTemplatePropertyKind; use crate::ui::Ui; /// Show the operation log @@ -139,7 +140,7 @@ fn do_op_log( ui, &language, &text, - OperationTemplateLanguage::wrap_operation, + OperationTemplatePropertyKind::wrap_operation, )? .labeled("operation") .labeled("op_log"); @@ -148,7 +149,7 @@ fn do_op_log( ui, &language, &get_node_template(graph_style, settings)?, - OperationTemplateLanguage::wrap_operation, + OperationTemplatePropertyKind::wrap_operation, )? .labeled("node"); } @@ -173,7 +174,7 @@ fn do_op_log( ui, &language, &template_text, - CommitTemplateLanguage::wrap_commit, + CommitTemplatePropertyKind::wrap_commit, )? }; let path_converter = workspace_env.path_converter(); diff --git a/cli/src/commands/operation/show.rs b/cli/src/commands/operation/show.rs index b3c4ad1a5..a2e6c2153 100644 --- a/cli/src/commands/operation/show.rs +++ b/cli/src/commands/operation/show.rs @@ -19,7 +19,7 @@ use super::diff::show_op_diff; use crate::cli_util::CommandHelper; use crate::cli_util::LogContentFormat; use crate::command_error::CommandError; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::diff_util::diff_formats_for_log; use crate::diff_util::DiffFormatArgs; @@ -66,7 +66,12 @@ pub fn cmd_op_show( let commit_summary_template = { let language = workspace_env.commit_template_language(repo.as_ref(), &id_prefix_context); let text = settings.get_string("templates.commit_summary")?; - workspace_env.parse_template(ui, &language, &text, CommitTemplateLanguage::wrap_commit)? + workspace_env.parse_template( + ui, + &language, + &text, + CommitTemplatePropertyKind::wrap_commit, + )? }; let graph_style = GraphStyle::from_settings(settings)?; diff --git a/cli/src/commands/tag.rs b/cli/src/commands/tag.rs index b83648689..b5b3a6e3f 100644 --- a/cli/src/commands/tag.rs +++ b/cli/src/commands/tag.rs @@ -18,7 +18,7 @@ use jj_lib::str_util::StringPattern; use crate::cli_util::CommandHelper; use crate::command_error::CommandError; use crate::commit_templater::CommitRef; -use crate::commit_templater::CommitTemplateLanguage; +use crate::commit_templater::CommitTemplatePropertyKind; use crate::complete; use crate::ui::Ui; @@ -86,7 +86,7 @@ fn cmd_tag_list( ui, &language, &text, - CommitTemplateLanguage::wrap_commit_ref, + CommitTemplatePropertyKind::wrap_commit_ref, )? .labeled("tag_list") }; diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index a3ea18196..23896c96a 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -212,8 +212,8 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { build_ctx, property, function, - Self::wrap_commit, - Self::wrap_commit_list, + Self::Property::wrap_commit, + Self::Property::wrap_commit_list, ) } CommitTemplatePropertyKind::CommitRef(property) => { @@ -236,8 +236,8 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { build_ctx, property, function, - Self::wrap_commit_ref, - Self::wrap_commit_ref_list, + Self::Property::wrap_commit_ref, + Self::Property::wrap_commit_ref_list, ) } CommitTemplatePropertyKind::RepoPath(property) => { @@ -280,8 +280,8 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { build_ctx, property, function, - Self::wrap_tree_diff_entry, - Self::wrap_tree_diff_entry_list, + Self::Property::wrap_tree_diff_entry, + Self::Property::wrap_tree_diff_entry_list, ) } CommitTemplatePropertyKind::TreeEntry(property) => { @@ -323,7 +323,7 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { expect_plain_text_expression(self, diagnostics, build_ctx, key_node)?; let out_property = (property, key_property) .map(|(trailers, key)| trailers.iter().any(|t| t.key == key)); - Ok(Self::wrap_boolean(out_property.into_dyn())) + Ok(Self::Property::wrap_boolean(out_property.into_dyn())) } else { template_builder::build_formattable_list_method( self, @@ -331,8 +331,8 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { build_ctx, property, function, - Self::wrap_trailer, - Self::wrap_trailer_list, + Self::Property::wrap_trailer, + Self::Property::wrap_trailer_list, ) } } @@ -358,121 +358,6 @@ impl<'repo> CommitTemplateLanguage<'repo> { pub fn cache_extension(&self) -> Option<&T> { self.cache_extensions.get::() } - - // TODO: delete - pub fn wrap_commit( - property: BoxedTemplateProperty<'repo, Commit>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit(property) - } - - pub fn wrap_commit_opt( - property: BoxedTemplateProperty<'repo, Option>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit_opt(property) - } - - pub fn wrap_commit_list( - property: BoxedTemplateProperty<'repo, Vec>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit_list(property) - } - - pub fn wrap_commit_ref( - property: BoxedTemplateProperty<'repo, Rc>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit_ref(property) - } - - pub fn wrap_commit_ref_opt( - property: BoxedTemplateProperty<'repo, Option>>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit_ref_opt(property) - } - - pub fn wrap_commit_ref_list( - property: BoxedTemplateProperty<'repo, Vec>>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit_ref_list(property) - } - - pub fn wrap_repo_path( - property: BoxedTemplateProperty<'repo, RepoPathBuf>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_repo_path(property) - } - - pub fn wrap_repo_path_opt( - property: BoxedTemplateProperty<'repo, Option>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_repo_path_opt(property) - } - - pub fn wrap_commit_or_change_id( - property: BoxedTemplateProperty<'repo, CommitOrChangeId>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_commit_or_change_id(property) - } - - pub fn wrap_shortest_id_prefix( - property: BoxedTemplateProperty<'repo, ShortestIdPrefix>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_shortest_id_prefix(property) - } - - pub fn wrap_tree_diff( - property: BoxedTemplateProperty<'repo, TreeDiff>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_tree_diff(property) - } - - pub fn wrap_tree_diff_entry( - property: BoxedTemplateProperty<'repo, TreeDiffEntry>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_tree_diff_entry(property) - } - - pub fn wrap_tree_diff_entry_list( - property: BoxedTemplateProperty<'repo, Vec>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_tree_diff_entry_list(property) - } - - pub fn wrap_tree_entry( - property: BoxedTemplateProperty<'repo, TreeEntry>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_tree_entry(property) - } - - pub fn wrap_diff_stats( - property: BoxedTemplateProperty<'repo, DiffStatsFormatted<'repo>>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_diff_stats(property) - } - - fn wrap_cryptographic_signature_opt( - property: BoxedTemplateProperty<'repo, Option>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_cryptographic_signature_opt(property) - } - - pub fn wrap_annotation_line( - property: BoxedTemplateProperty<'repo, AnnotationLine>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_annotation_line(property) - } - - pub fn wrap_trailer( - property: BoxedTemplateProperty<'repo, Trailer>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_trailer(property) - } - - pub fn wrap_trailer_list( - property: BoxedTemplateProperty<'repo, Vec>, - ) -> CommitTemplatePropertyKind<'repo> { - CommitTemplatePropertyKind::wrap_trailer_list(property) - } } pub enum CommitTemplatePropertyKind<'repo> { @@ -846,7 +731,7 @@ impl<'repo> CommitKeywordCache<'repo> { } fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Commit> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -856,7 +741,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let out_property = self_property.map(|commit| text_util::complete_newline(commit.description())); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -865,7 +750,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let out_property = self_property .map(|commit| trailer::parse_description_trailers(commit.description())); - Ok(L::wrap_trailer_list(out_property.into_dyn())) + Ok(P::wrap_trailer_list(out_property.into_dyn())) }, ); map.insert( @@ -874,7 +759,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let out_property = self_property.map(|commit| CommitOrChangeId::Change(commit.change_id().to_owned())); - Ok(L::wrap_commit_or_change_id(out_property.into_dyn())) + Ok(P::wrap_commit_or_change_id(out_property.into_dyn())) }, ); map.insert( @@ -883,7 +768,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let out_property = self_property.map(|commit| CommitOrChangeId::Commit(commit.id().to_owned())); - Ok(L::wrap_commit_or_change_id(out_property.into_dyn())) + Ok(P::wrap_commit_or_change_id(out_property.into_dyn())) }, ); map.insert( @@ -892,7 +777,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let out_property = self_property.and_then(|commit| Ok(commit.parents().try_collect()?)); - Ok(L::wrap_commit_list(out_property.into_dyn())) + Ok(P::wrap_commit_list(out_property.into_dyn())) }, ); map.insert( @@ -900,7 +785,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit| commit.author().clone()); - Ok(L::wrap_signature(out_property.into_dyn())) + Ok(P::wrap_signature(out_property.into_dyn())) }, ); map.insert( @@ -908,7 +793,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit| commit.committer().clone()); - Ok(L::wrap_signature(out_property.into_dyn())) + Ok(P::wrap_signature(out_property.into_dyn())) }, ); map.insert( @@ -917,7 +802,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let user_email = language.revset_parse_context.user_email.to_owned(); let out_property = self_property.map(move |commit| commit.author().email == user_email); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -925,7 +810,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(CryptographicSignature::new); - Ok(L::wrap_cryptographic_signature_opt(out_property.into_dyn())) + Ok(P::wrap_cryptographic_signature_opt(out_property.into_dyn())) }, ); map.insert( @@ -934,7 +819,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let repo = language.repo; let out_property = self_property.map(|commit| extract_working_copies(repo, &commit)); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -945,7 +830,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm let name = language.workspace_name.clone(); let out_property = self_property .map(move |commit| Some(commit.id()) == repo.view().get_wc_commit_id(&name)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -964,7 +849,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm .cloned() .collect() }); - Ok(L::wrap_commit_ref_list(out_property.into_dyn())) + Ok(P::wrap_commit_ref_list(out_property.into_dyn())) }, ); map.insert( @@ -983,7 +868,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm .cloned() .collect() }); - Ok(L::wrap_commit_ref_list(out_property.into_dyn())) + Ok(P::wrap_commit_ref_list(out_property.into_dyn())) }, ); map.insert( @@ -1002,7 +887,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm .cloned() .collect() }); - Ok(L::wrap_commit_ref_list(out_property.into_dyn())) + Ok(P::wrap_commit_ref_list(out_property.into_dyn())) }, ); map.insert( @@ -1011,7 +896,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let index = language.keyword_cache.tags_index(language.repo).clone(); let out_property = self_property.map(move |commit| index.get(commit.id()).to_vec()); - Ok(L::wrap_commit_ref_list(out_property.into_dyn())) + Ok(P::wrap_commit_ref_list(out_property.into_dyn())) }, ); map.insert( @@ -1020,7 +905,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let index = language.keyword_cache.git_refs_index(language.repo).clone(); let out_property = self_property.map(move |commit| index.get(commit.id()).to_vec()); - Ok(L::wrap_commit_ref_list(out_property.into_dyn())) + Ok(P::wrap_commit_ref_list(out_property.into_dyn())) }, ); map.insert( @@ -1032,7 +917,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm let target = repo.view().git_head(); target.added_ids().contains(commit.id()) }); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1045,7 +930,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm let maybe_entries = repo.resolve_change_id(commit.change_id()); maybe_entries.map_or(0, |entries| entries.len()) > 1 }); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1054,7 +939,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let repo = language.repo; let out_property = self_property.map(|commit| commit.is_hidden(repo)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1066,7 +951,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm .is_immutable_fn(language, function.name_span)? .clone(); let out_property = self_property.and_then(move |commit| Ok(is_immutable(commit.id())?)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1080,7 +965,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm })?; let out_property = self_property.and_then(move |commit| Ok(is_contained(commit.id())?)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1088,7 +973,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|commit| Ok(commit.has_conflict()?)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1097,7 +982,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm function.expect_no_arguments()?; let repo = language.repo; let out_property = self_property.and_then(|commit| Ok(commit.is_empty(repo)?)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1115,7 +1000,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm let matcher: Rc = files.to_matcher().into(); let out_property = self_property .and_then(move |commit| Ok(TreeDiff::from_commit(repo, &commit, matcher.clone())?)); - Ok(L::wrap_tree_diff(out_property.into_dyn())) + Ok(P::wrap_tree_diff(out_property.into_dyn())) }, ); map.insert( @@ -1125,7 +1010,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm let repo = language.repo; let out_property = self_property.map(|commit| commit.id() == repo.store().root_commit_id()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map @@ -1415,7 +1300,7 @@ impl Template for Vec> { } fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Rc> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::>::new(); @@ -1424,7 +1309,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit_ref| commit_ref.name.clone()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1433,7 +1318,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, function.expect_no_arguments()?; let out_property = self_property.map(|commit_ref| commit_ref.remote.clone().unwrap_or_default()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1441,7 +1326,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit_ref| commit_ref.is_present()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1449,7 +1334,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit_ref| commit_ref.has_conflict()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1461,7 +1346,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, let maybe_id = commit_ref.target.as_normal(); Ok(maybe_id.map(|id| repo.store().get_commit(id)).transpose()?) }); - Ok(L::wrap_commit_opt(out_property.into_dyn())) + Ok(P::wrap_commit_opt(out_property.into_dyn())) }, ); map.insert( @@ -1473,7 +1358,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, let ids = commit_ref.target.removed_ids(); Ok(ids.map(|id| repo.store().get_commit(id)).try_collect()?) }); - Ok(L::wrap_commit_list(out_property.into_dyn())) + Ok(P::wrap_commit_list(out_property.into_dyn())) }, ); map.insert( @@ -1485,7 +1370,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, let ids = commit_ref.target.added_ids(); Ok(ids.map(|id| repo.store().get_commit(id)).try_collect()?) }); - Ok(L::wrap_commit_list(out_property.into_dyn())) + Ok(P::wrap_commit_list(out_property.into_dyn())) }, ); map.insert( @@ -1493,7 +1378,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit_ref| commit_ref.is_tracked()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1501,7 +1386,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|commit_ref| commit_ref.is_tracking_present()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1511,7 +1396,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, let repo = language.repo; let out_property = self_property.and_then(|commit_ref| commit_ref.tracking_ahead_count(repo)); - Ok(L::wrap_size_hint(out_property.into_dyn())) + Ok(P::wrap_size_hint(out_property.into_dyn())) }, ); map.insert( @@ -1521,7 +1406,7 @@ fn builtin_commit_ref_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, let repo = language.repo; let out_property = self_property.and_then(|commit_ref| commit_ref.tracking_behind_count(repo)); - Ok(L::wrap_size_hint(out_property.into_dyn())) + Ok(P::wrap_size_hint(out_property.into_dyn())) }, ); map @@ -1586,7 +1471,7 @@ impl Template for RepoPathBuf { } fn builtin_repo_path_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, RepoPathBuf> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -1596,7 +1481,7 @@ fn builtin_repo_path_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, R function.expect_no_arguments()?; let path_converter = language.path_converter; let out_property = self_property.map(|path| path_converter.format_file_path(&path)); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1604,7 +1489,7 @@ fn builtin_repo_path_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, R |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|path| Some(path.parent()?.to_owned())); - Ok(L::wrap_repo_path_opt(out_property.into_dyn())) + Ok(P::wrap_repo_path_opt(out_property.into_dyn())) }, ); map @@ -1657,7 +1542,7 @@ impl Template for CommitOrChangeId { fn builtin_commit_or_change_id_methods<'repo>( ) -> CommitTemplateBuildMethodFnMap<'repo, CommitOrChangeId> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -1674,7 +1559,7 @@ fn builtin_commit_or_change_id_methods<'repo>( CommitOrChangeId::Change(id) => id.hex(), } }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1693,7 +1578,7 @@ fn builtin_commit_or_change_id_methods<'repo>( .transpose()?; let out_property = (self_property, len_property).map(|(id, len)| id.short(len.unwrap_or(12))); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1728,7 +1613,7 @@ fn builtin_commit_or_change_id_methods<'repo>( }; let out_property = (self_property, len_property) .map(move |(id, len)| id.shortest(repo, &index, len.unwrap_or(0))); - Ok(L::wrap_shortest_id_prefix(out_property.into_dyn())) + Ok(P::wrap_shortest_id_prefix(out_property.into_dyn())) }, ); map @@ -1764,7 +1649,7 @@ impl ShortestIdPrefix { fn builtin_shortest_id_prefix_methods<'repo>( ) -> CommitTemplateBuildMethodFnMap<'repo, ShortestIdPrefix> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -1773,7 +1658,7 @@ fn builtin_shortest_id_prefix_methods<'repo>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|id| id.prefix); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1781,7 +1666,7 @@ fn builtin_shortest_id_prefix_methods<'repo>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|id| id.rest); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1789,7 +1674,7 @@ fn builtin_shortest_id_prefix_methods<'repo>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|id| id.to_upper()); - Ok(L::wrap_shortest_id_prefix(out_property.into_dyn())) + Ok(P::wrap_shortest_id_prefix(out_property.into_dyn())) }, ); map.insert( @@ -1797,7 +1682,7 @@ fn builtin_shortest_id_prefix_methods<'repo>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|id| id.to_lower()); - Ok(L::wrap_shortest_id_prefix(out_property.into_dyn())) + Ok(P::wrap_shortest_id_prefix(out_property.into_dyn())) }, ); map @@ -1873,7 +1758,7 @@ where } fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, TreeDiff> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -1884,7 +1769,7 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T // TODO: cache and reuse diff entries within the current evaluation? let out_property = self_property.and_then(|diff| Ok(diff.collect_entries().block_on()?)); - Ok(L::wrap_tree_diff_entry_list(out_property.into_dyn())) + Ok(P::wrap_tree_diff_entry_list(out_property.into_dyn())) }, ); map.insert( @@ -1926,7 +1811,7 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T }) }) .into_template(); - Ok(L::wrap_template(template)) + Ok(P::wrap_template(template)) }, ); map.insert( @@ -1966,7 +1851,7 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T }) }) .into_template(); - Ok(L::wrap_template(template)) + Ok(P::wrap_template(template)) }, ); map.insert( @@ -2000,7 +1885,7 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T width: width.unwrap_or(80), }) }); - Ok(L::wrap_diff_stats(out_property.into_dyn())) + Ok(P::wrap_diff_stats(out_property.into_dyn())) }, ); map.insert( @@ -2015,7 +1900,7 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T }) }) .into_template(); - Ok(L::wrap_template(template)) + Ok(P::wrap_template(template)) }, ); // TODO: add support for external tools @@ -2066,7 +1951,7 @@ impl TreeDiffEntry { fn builtin_tree_diff_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, TreeDiffEntry> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -2075,7 +1960,7 @@ fn builtin_tree_diff_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|entry| entry.path.target); - Ok(L::wrap_repo_path(out_property.into_dyn())) + Ok(P::wrap_repo_path(out_property.into_dyn())) }, ); map.insert( @@ -2083,7 +1968,7 @@ fn builtin_tree_diff_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|entry| entry.status_label().to_owned()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); // TODO: add status_code() or status_char()? @@ -2092,7 +1977,7 @@ fn builtin_tree_diff_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(TreeDiffEntry::into_source_entry); - Ok(L::wrap_tree_entry(out_property.into_dyn())) + Ok(P::wrap_tree_entry(out_property.into_dyn())) }, ); map.insert( @@ -2100,7 +1985,7 @@ fn builtin_tree_diff_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(TreeDiffEntry::into_target_entry); - Ok(L::wrap_tree_entry(out_property.into_dyn())) + Ok(P::wrap_tree_entry(out_property.into_dyn())) }, ); map @@ -2114,7 +1999,7 @@ pub struct TreeEntry { } fn builtin_tree_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, TreeEntry> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -2123,7 +2008,7 @@ fn builtin_tree_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|entry| entry.path); - Ok(L::wrap_repo_path(out_property.into_dyn())) + Ok(P::wrap_repo_path(out_property.into_dyn())) }, ); map.insert( @@ -2131,7 +2016,7 @@ fn builtin_tree_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|entry| !entry.value.is_resolved()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -2140,7 +2025,7 @@ fn builtin_tree_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, function.expect_no_arguments()?; let out_property = self_property.map(|entry| describe_file_type(&entry.value).to_owned()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -2149,7 +2034,7 @@ fn builtin_tree_entry_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, function.expect_no_arguments()?; let out_property = self_property.map(|entry| is_executable_file(&entry.value).unwrap_or_default()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map @@ -2191,7 +2076,7 @@ impl Template for DiffStatsFormatted<'_> { } fn builtin_diff_stats_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, DiffStats> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -2202,7 +2087,7 @@ fn builtin_diff_stats_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, function.expect_no_arguments()?; let out_property = self_property.and_then(|stats| Ok(stats.count_total_added().try_into()?)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); map.insert( @@ -2211,7 +2096,7 @@ fn builtin_diff_stats_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, function.expect_no_arguments()?; let out_property = self_property.and_then(|stats| Ok(stats.count_total_removed().try_into()?)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); map @@ -2253,7 +2138,7 @@ impl CryptographicSignature { fn builtin_cryptographic_signature_methods<'repo>( ) -> CommitTemplateBuildMethodFnMap<'repo, CryptographicSignature> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = CommitTemplateBuildMethodFnMap::::new(); @@ -2266,7 +2151,7 @@ fn builtin_cryptographic_signature_methods<'repo>( Err(SignError::InvalidSignatureFormat) => Ok("invalid".to_string()), Err(err) => Err(err.into()), }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -2274,7 +2159,7 @@ fn builtin_cryptographic_signature_methods<'repo>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|sig| Ok(sig.key()?)); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -2282,7 +2167,7 @@ fn builtin_cryptographic_signature_methods<'repo>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|sig| Ok(sig.display()?)); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map @@ -2298,14 +2183,14 @@ pub struct AnnotationLine { fn builtin_annotation_line_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, AnnotationLine> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; let mut map = CommitTemplateBuildMethodFnMap::::new(); map.insert( "commit", |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|line| line.commit); - Ok(L::wrap_commit(out_property.into_dyn())) + Ok(P::wrap_commit(out_property.into_dyn())) }, ); map.insert( @@ -2314,7 +2199,7 @@ fn builtin_annotation_line_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r function.expect_no_arguments()?; let out_property = self_property.map(|line| line.content); // TODO: Add Bytes or BString template type? - Ok(L::wrap_template(out_property.into_template())) + Ok(P::wrap_template(out_property.into_template())) }, ); map.insert( @@ -2322,7 +2207,7 @@ fn builtin_annotation_line_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|line| Ok(line.line_number.try_into()?)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(P::wrap_integer(out_property.into_dyn())) }, ); map.insert( @@ -2330,7 +2215,7 @@ fn builtin_annotation_line_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'r |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|line| line.first_line_in_hunk); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map @@ -2349,14 +2234,14 @@ impl Template for Vec { } fn builtin_trailer_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Trailer> { - type L<'repo> = CommitTemplateLanguage<'repo>; + type P<'repo> = CommitTemplatePropertyKind<'repo>; let mut map = CommitTemplateBuildMethodFnMap::::new(); map.insert( "key", |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|trailer| trailer.key); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -2364,7 +2249,7 @@ fn builtin_trailer_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Tra |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|trailer| trailer.value); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map diff --git a/cli/src/generic_templater.rs b/cli/src/generic_templater.rs index 544e260ef..843705f18 100644 --- a/cli/src/generic_templater.rs +++ b/cli/src/generic_templater.rs @@ -129,13 +129,6 @@ impl<'a, C> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C> { } } -impl<'a, C> GenericTemplateLanguage<'a, C> { - // TODO: delete - pub fn wrap_self(property: BoxedTemplateProperty<'a, C>) -> GenericTemplatePropertyKind<'a, C> { - GenericTemplatePropertyKind::wrap_self(property) - } -} - pub enum GenericTemplatePropertyKind<'a, C> { Core(CoreTemplatePropertyKind<'a>), Self_(BoxedTemplateProperty<'a, C>), diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index e16b2b9bd..d3cac3930 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -134,19 +134,6 @@ impl OperationTemplateLanguage { pub fn cache_extension(&self) -> Option<&T> { self.cache_extensions.get::() } - - // TODO: delete - pub fn wrap_operation( - property: BoxedTemplateProperty<'static, Operation>, - ) -> OperationTemplatePropertyKind { - OperationTemplatePropertyKind::wrap_operation(property) - } - - pub fn wrap_operation_id( - property: BoxedTemplateProperty<'static, OperationId>, - ) -> OperationTemplatePropertyKind { - OperationTemplatePropertyKind::wrap_operation_id(property) - } } pub enum OperationTemplatePropertyKind { @@ -276,7 +263,7 @@ impl OperationTemplateBuildFnTable { } fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { - type L = OperationTemplateLanguage; + type P = OperationTemplatePropertyKind; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = OperationTemplateBuildMethodFnMap::::new(); @@ -286,7 +273,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { function.expect_no_arguments()?; let current_op_id = language.current_op_id.clone(); let out_property = self_property.map(move |op| Some(op.id()) == current_op_id.as_ref()); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -294,7 +281,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|op| op.metadata().description.clone()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -302,7 +289,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|op| op.id().clone()); - Ok(L::wrap_operation_id(out_property.into_dyn())) + Ok(P::wrap_operation_id(out_property.into_dyn())) }, ); map.insert( @@ -317,7 +304,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { .map(|(key, value)| format!("{key}: {value}")) .join("\n") }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -325,7 +312,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|op| op.metadata().is_snapshot); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -336,7 +323,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { start: op.metadata().start_time, end: op.metadata().end_time, }); - Ok(L::wrap_timestamp_range(out_property.into_dyn())) + Ok(P::wrap_timestamp_range(out_property.into_dyn())) }, ); map.insert( @@ -347,7 +334,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { // TODO: introduce dedicated type and provide accessors? format!("{}@{}", op.metadata().username, op.metadata().hostname) }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(P::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -356,7 +343,7 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { function.expect_no_arguments()?; let root_op_id = language.repo_loader.op_store().root_operation_id().clone(); let out_property = self_property.map(move |op| op.id() == &root_op_id); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(P::wrap_boolean(out_property.into_dyn())) }, ); map @@ -369,7 +356,7 @@ impl Template for OperationId { } fn builtin_operation_id_methods() -> OperationTemplateBuildMethodFnMap { - type L = OperationTemplateLanguage; + type P = OperationTemplatePropertyKind; // Not using maplit::hashmap!{} or custom declarative macro here because // code completion inside macro is quite restricted. let mut map = OperationTemplateBuildMethodFnMap::::new(); @@ -392,7 +379,7 @@ fn builtin_operation_id_methods() -> OperationTemplateBuildMethodFnMap { type Property: CoreTemplatePropertyVar<'a> + IntoTemplateProperty<'a>; - // TODO: delete - fn wrap_string(property: BoxedTemplateProperty<'a, String>) -> Self::Property { - Self::Property::wrap_string(property) - } - fn wrap_string_list(property: BoxedTemplateProperty<'a, Vec>) -> Self::Property { - Self::Property::wrap_string_list(property) - } - fn wrap_boolean(property: BoxedTemplateProperty<'a, bool>) -> Self::Property { - Self::Property::wrap_boolean(property) - } - fn wrap_integer(property: BoxedTemplateProperty<'a, i64>) -> Self::Property { - Self::Property::wrap_integer(property) - } - fn wrap_integer_opt(property: BoxedTemplateProperty<'a, Option>) -> Self::Property { - Self::Property::wrap_integer_opt(property) - } - fn wrap_config_value(property: BoxedTemplateProperty<'a, ConfigValue>) -> Self::Property { - Self::Property::wrap_config_value(property) - } - fn wrap_signature(property: BoxedTemplateProperty<'a, Signature>) -> Self::Property { - Self::Property::wrap_signature(property) - } - fn wrap_email(property: BoxedTemplateProperty<'a, Email>) -> Self::Property { - Self::Property::wrap_email(property) - } - fn wrap_size_hint(property: BoxedTemplateProperty<'a, SizeHint>) -> Self::Property { - Self::Property::wrap_size_hint(property) - } - fn wrap_timestamp(property: BoxedTemplateProperty<'a, Timestamp>) -> Self::Property { - Self::Property::wrap_timestamp(property) - } - fn wrap_timestamp_range(property: BoxedTemplateProperty<'a, TimestampRange>) -> Self::Property { - Self::Property::wrap_timestamp_range(property) - } - - // TODO: delete - fn wrap_template(template: Box) -> Self::Property { - Self::Property::wrap_template(template) - } - fn wrap_list_template(template: Box) -> Self::Property { - Self::Property::wrap_list_template(template) - } - fn settings(&self) -> &UserSettings; /// Translates the given global `function` call to a property. @@ -553,8 +510,8 @@ impl<'a, L: TemplateLanguage<'a> + ?Sized> CoreTemplateBuildFnTable<'a, L> { build_ctx, property, function, - L::wrap_string, - L::wrap_string_list, + L::Property::wrap_string, + L::Property::wrap_string_list, ) } CoreTemplatePropertyKind::Boolean(property) => { @@ -731,7 +688,7 @@ fn build_unary_operation<'a, L: TemplateLanguage<'a> + ?Sized>( match op { UnaryOp::LogicalNot => { let arg = expect_boolean_expression(language, diagnostics, build_ctx, arg_node)?; - Ok(L::wrap_boolean(arg.map(|v| !v).into_dyn())) + Ok(L::Property::wrap_boolean(arg.map(|v| !v).into_dyn())) } UnaryOp::Negate => { let arg = expect_integer_expression(language, diagnostics, build_ctx, arg_node)?; @@ -739,7 +696,7 @@ fn build_unary_operation<'a, L: TemplateLanguage<'a> + ?Sized>( v.checked_neg() .ok_or_else(|| TemplatePropertyError("Attempt to negate with overflow".into())) }); - Ok(L::wrap_integer(out.into_dyn())) + Ok(L::Property::wrap_integer(out.into_dyn())) } } } @@ -758,13 +715,13 @@ fn build_binary_operation<'a, L: TemplateLanguage<'a> + ?Sized>( let lhs = expect_boolean_expression(language, diagnostics, build_ctx, lhs_node)?; let rhs = expect_boolean_expression(language, diagnostics, build_ctx, rhs_node)?; let out = lhs.and_then(move |l| Ok(l || rhs.extract()?)); - Ok(L::wrap_boolean(out.into_dyn())) + Ok(L::Property::wrap_boolean(out.into_dyn())) } BinaryOp::LogicalAnd => { let lhs = expect_boolean_expression(language, diagnostics, build_ctx, lhs_node)?; let rhs = expect_boolean_expression(language, diagnostics, build_ctx, rhs_node)?; let out = lhs.and_then(move |l| Ok(l && rhs.extract()?)); - Ok(L::wrap_boolean(out.into_dyn())) + Ok(L::Property::wrap_boolean(out.into_dyn())) } BinaryOp::Eq | BinaryOp::Ne => { let lhs = build_expression(language, diagnostics, build_ctx, lhs_node)?; @@ -780,7 +737,7 @@ fn build_binary_operation<'a, L: TemplateLanguage<'a> + ?Sized>( BinaryOp::Ne => eq.map(|eq| !eq).into_dyn(), _ => unreachable!(), }; - Ok(L::wrap_boolean(out)) + Ok(L::Property::wrap_boolean(out)) } BinaryOp::Ge | BinaryOp::Gt | BinaryOp::Le | BinaryOp::Lt => { let lhs = build_expression(language, diagnostics, build_ctx, lhs_node)?; @@ -798,7 +755,7 @@ fn build_binary_operation<'a, L: TemplateLanguage<'a> + ?Sized>( BinaryOp::Lt => cmp.map(|ordering| ordering.is_lt()).into_dyn(), _ => unreachable!(), }; - Ok(L::wrap_boolean(out)) + Ok(L::Property::wrap_boolean(out)) } } } @@ -813,7 +770,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|s| Ok(s.len().try_into()?)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(L::Property::wrap_integer(out_property.into_dyn())) }, ); map.insert( @@ -825,7 +782,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( expect_plain_text_expression(language, diagnostics, build_ctx, needle_node)?; let out_property = (self_property, needle_property) .map(|(haystack, needle)| haystack.contains(&needle)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(L::Property::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -836,7 +793,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( expect_plain_text_expression(language, diagnostics, build_ctx, needle_node)?; let out_property = (self_property, needle_property) .map(|(haystack, needle)| haystack.starts_with(&needle)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(L::Property::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -847,7 +804,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( expect_plain_text_expression(language, diagnostics, build_ctx, needle_node)?; let out_property = (self_property, needle_property) .map(|(haystack, needle)| haystack.ends_with(&needle)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(L::Property::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -862,7 +819,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( .map(ToOwned::to_owned) .unwrap_or(haystack) }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -877,7 +834,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( .map(ToOwned::to_owned) .unwrap_or(haystack) }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -885,7 +842,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| s.trim().to_owned()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -893,7 +850,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| s.trim_start().to_owned()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -901,7 +858,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| s.trim_end().to_owned()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -919,7 +876,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( s.get(start_idx..end_idx).unwrap_or_default().to_owned() }, ); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -928,7 +885,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( function.expect_no_arguments()?; let out_property = self_property.map(|s| s.lines().next().unwrap_or_default().to_string()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -936,7 +893,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| s.lines().map(|l| l.to_owned()).collect()); - Ok(L::wrap_string_list(out_property.into_dyn())) + Ok(L::Property::wrap_string_list(out_property.into_dyn())) }, ); map.insert( @@ -944,7 +901,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| s.to_uppercase()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -952,7 +909,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| s.to_lowercase()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -960,7 +917,7 @@ fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|s| serde_json::to_string(&s).unwrap()); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map @@ -1002,7 +959,7 @@ fn builtin_config_value_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(extract); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(L::Property::wrap_boolean(out_property.into_dyn())) }, ); map.insert( @@ -1010,7 +967,7 @@ fn builtin_config_value_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(extract); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(L::Property::wrap_integer(out_property.into_dyn())) }, ); map.insert( @@ -1018,7 +975,7 @@ fn builtin_config_value_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(extract); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1026,7 +983,7 @@ fn builtin_config_value_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(extract); - Ok(L::wrap_string_list(out_property.into_dyn())) + Ok(L::Property::wrap_string_list(out_property.into_dyn())) }, ); // TODO: add is_() -> Boolean? @@ -1044,7 +1001,7 @@ fn builtin_signature_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|signature| signature.name); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1052,7 +1009,7 @@ fn builtin_signature_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|signature| signature.email.into()); - Ok(L::wrap_email(out_property.into_dyn())) + Ok(L::Property::wrap_email(out_property.into_dyn())) }, ); map.insert( @@ -1068,7 +1025,7 @@ fn builtin_signature_methods<'a, L: TemplateLanguage<'a> + ?Sized>( let (username, _) = text_util::split_email(&signature.email); username.to_owned() }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1076,7 +1033,7 @@ fn builtin_signature_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|signature| signature.timestamp); - Ok(L::wrap_timestamp(out_property.into_dyn())) + Ok(L::Property::wrap_timestamp(out_property.into_dyn())) }, ); map @@ -1095,7 +1052,7 @@ fn builtin_email_methods<'a, L: TemplateLanguage<'a> + ?Sized>( let (local, _) = text_util::split_email(&email.0); local.to_owned() }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1106,7 +1063,7 @@ fn builtin_email_methods<'a, L: TemplateLanguage<'a> + ?Sized>( let (_, domain) = text_util::split_email(&email.0); domain.unwrap_or_default().to_owned() }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map @@ -1122,7 +1079,7 @@ fn builtin_size_hint_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|(lower, _)| Ok(i64::try_from(lower)?)); - Ok(L::wrap_integer(out_property.into_dyn())) + Ok(L::Property::wrap_integer(out_property.into_dyn())) }, ); map.insert( @@ -1131,7 +1088,7 @@ fn builtin_size_hint_methods<'a, L: TemplateLanguage<'a> + ?Sized>( function.expect_no_arguments()?; let out_property = self_property.and_then(|(_, upper)| Ok(upper.map(i64::try_from).transpose()?)); - Ok(L::wrap_integer_opt(out_property.into_dyn())) + Ok(L::Property::wrap_integer_opt(out_property.into_dyn())) }, ); map.insert( @@ -1142,7 +1099,7 @@ fn builtin_size_hint_methods<'a, L: TemplateLanguage<'a> + ?Sized>( let exact = (Some(lower) == upper).then_some(lower); Ok(exact.map(i64::try_from).transpose()?) }); - Ok(L::wrap_integer_opt(out_property.into_dyn())) + Ok(L::Property::wrap_integer_opt(out_property.into_dyn())) }, ); map.insert( @@ -1150,7 +1107,7 @@ fn builtin_size_hint_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|(_, upper)| upper == Some(0)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(L::Property::wrap_boolean(out_property.into_dyn())) }, ); map @@ -1170,7 +1127,7 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a> + ?Sized>( let out_property = self_property.and_then(move |timestamp| { Ok(time_util::format_duration(×tamp, &now, &format)?) }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1189,7 +1146,7 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a> + ?Sized>( ×tamp, &format, )?) }); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map.insert( @@ -1200,7 +1157,7 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a> + ?Sized>( timestamp.tz_offset = 0; timestamp }); - Ok(L::wrap_timestamp(out_property.into_dyn())) + Ok(L::Property::wrap_timestamp(out_property.into_dyn())) }, ); map.insert( @@ -1215,7 +1172,7 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a> + ?Sized>( timestamp.tz_offset = tz_offset; timestamp }); - Ok(L::wrap_timestamp(out_property.into_dyn())) + Ok(L::Property::wrap_timestamp(out_property.into_dyn())) }, ); map.insert( @@ -1233,7 +1190,7 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a> + ?Sized>( }, )?; let out_property = self_property.map(move |timestamp| date_pattern.matches(×tamp)); - Ok(L::wrap_boolean(out_property.into_dyn())) + Ok(L::Property::wrap_boolean(out_property.into_dyn())) }, ); map.insert("before", map["after"]); @@ -1250,7 +1207,7 @@ fn builtin_timestamp_range_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|time_range| time_range.start); - Ok(L::wrap_timestamp(out_property.into_dyn())) + Ok(L::Property::wrap_timestamp(out_property.into_dyn())) }, ); map.insert( @@ -1258,7 +1215,7 @@ fn builtin_timestamp_range_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|time_range| time_range.end); - Ok(L::wrap_timestamp(out_property.into_dyn())) + Ok(L::Property::wrap_timestamp(out_property.into_dyn())) }, ); map.insert( @@ -1266,7 +1223,7 @@ fn builtin_timestamp_range_methods<'a, L: TemplateLanguage<'a> + ?Sized>( |_language, _diagnostics, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.and_then(|time_range| Ok(time_range.duration()?)); - Ok(L::wrap_string(out_property.into_dyn())) + Ok(L::Property::wrap_string(out_property.into_dyn())) }, ); map @@ -1284,7 +1241,7 @@ fn build_list_template_method<'a, L: TemplateLanguage<'a> + ?Sized>( let [separator_node] = function.expect_exact_arguments()?; let separator = expect_template_expression(language, diagnostics, build_ctx, separator_node)?; - L::wrap_template(self_template.join(separator)) + L::Property::wrap_template(self_template.join(separator)) } _ => return Err(TemplateParseError::no_such_method("ListTemplate", function)), }; @@ -1311,7 +1268,7 @@ where "len" => { function.expect_no_arguments()?; let out_property = self_property.and_then(|items| Ok(items.len().try_into()?)); - L::wrap_integer(out_property.into_dyn()) + L::Property::wrap_integer(out_property.into_dyn()) } "join" => { let [separator_node] = function.expect_exact_arguments()?; @@ -1321,7 +1278,7 @@ where ListPropertyTemplate::new(self_property, separator, |formatter, item| { item.format(formatter) }); - L::wrap_template(Box::new(template)) + L::Property::wrap_template(Box::new(template)) } "filter" => build_filter_operation( language, @@ -1362,7 +1319,7 @@ where "len" => { function.expect_no_arguments()?; let out_property = self_property.and_then(|items| Ok(items.len().try_into()?)); - L::wrap_integer(out_property.into_dyn()) + L::Property::wrap_integer(out_property.into_dyn()) } // No "join" "filter" => build_filter_operation( @@ -1467,7 +1424,7 @@ where item_placeholder.with_value(item, || item_template.format(formatter)) }, ); - Ok(L::wrap_list_template(Box::new(list_template))) + Ok(L::Property::wrap_list_template(Box::new(list_template))) } /// Builds lambda expression to be evaluated with the provided arguments. @@ -1506,7 +1463,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun Ok(width) => text_util::write_wrapped(formatter.as_mut(), recorded, width), Err(err) => formatter.handle_error(err), }); - Ok(L::wrap_template(Box::new(template))) + Ok(L::Property::wrap_template(Box::new(template))) }); map.insert("indent", |language, diagnostics, build_ctx, function| { let [prefix_node, content_node] = function.expect_exact_arguments()?; @@ -1518,7 +1475,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun prefix.format(&mut rewrap(formatter)) }) }); - Ok(L::wrap_template(Box::new(template))) + Ok(L::Property::wrap_template(Box::new(template))) }); map.insert("pad_start", |language, diagnostics, build_ctx, function| { let ([width_node, content_node], [fill_char_node]) = @@ -1529,7 +1486,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .transpose()?; let template = new_pad_template(content, fill_char, width, text_util::write_padded_start); - Ok(L::wrap_template(template)) + Ok(L::Property::wrap_template(template)) }); map.insert("pad_end", |language, diagnostics, build_ctx, function| { let ([width_node, content_node], [fill_char_node]) = @@ -1540,7 +1497,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .transpose()?; let template = new_pad_template(content, fill_char, width, text_util::write_padded_end); - Ok(L::wrap_template(template)) + Ok(L::Property::wrap_template(template)) }); map.insert( "pad_centered", @@ -1555,7 +1512,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .transpose()?; let template = new_pad_template(content, fill_char, width, text_util::write_padded_centered); - Ok(L::wrap_template(template)) + Ok(L::Property::wrap_template(template)) }, ); map.insert( @@ -1571,7 +1528,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .transpose()?; let template = new_truncate_template(content, ellipsis, width, text_util::write_truncated_start); - Ok(L::wrap_template(template)) + Ok(L::Property::wrap_template(template)) }, ); map.insert( @@ -1587,7 +1544,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .transpose()?; let template = new_truncate_template(content, ellipsis, width, text_util::write_truncated_end); - Ok(L::wrap_template(template)) + Ok(L::Property::wrap_template(template)) }, ); map.insert("label", |language, diagnostics, build_ctx, function| { @@ -1597,7 +1554,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun let content = expect_template_expression(language, diagnostics, build_ctx, content_node)?; let labels = label_property.map(|s| s.split_whitespace().map(ToString::to_string).collect()); - Ok(L::wrap_template(Box::new(LabelTemplate::new( + Ok(L::Property::wrap_template(Box::new(LabelTemplate::new( content, labels, )))) }); @@ -1607,15 +1564,15 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun let [content_node] = function.expect_exact_arguments()?; let content = expect_template_expression(language, diagnostics, build_ctx, content_node)?; - Ok(L::wrap_template(Box::new(RawEscapeSequenceTemplate( - content, - )))) + Ok(L::Property::wrap_template(Box::new( + RawEscapeSequenceTemplate(content), + ))) }, ); map.insert("stringify", |language, diagnostics, build_ctx, function| { let [content_node] = function.expect_exact_arguments()?; let content = expect_plain_text_expression(language, diagnostics, build_ctx, content_node)?; - Ok(L::wrap_string(content)) + Ok(L::Property::wrap_string(content)) }); map.insert("if", |language, diagnostics, build_ctx, function| { let ([condition_node, true_node], [false_node]) = function.expect_arguments()?; @@ -1627,7 +1584,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .transpose()?; let template = ConditionalTemplate::new(condition, true_template, false_template); - Ok(L::wrap_template(Box::new(template))) + Ok(L::Property::wrap_template(Box::new(template))) }); map.insert("coalesce", |language, diagnostics, build_ctx, function| { let contents = function @@ -1635,7 +1592,9 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .iter() .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .try_collect()?; - Ok(L::wrap_template(Box::new(CoalesceTemplate(contents)))) + Ok(L::Property::wrap_template(Box::new(CoalesceTemplate( + contents, + )))) }); map.insert("concat", |language, diagnostics, build_ctx, function| { let contents = function @@ -1643,7 +1602,9 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .iter() .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .try_collect()?; - Ok(L::wrap_template(Box::new(ConcatTemplate(contents)))) + Ok(L::Property::wrap_template(Box::new(ConcatTemplate( + contents, + )))) }); map.insert("separate", |language, diagnostics, build_ctx, function| { let ([separator_node], content_nodes) = function.expect_some_arguments()?; @@ -1653,7 +1614,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .iter() .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .try_collect()?; - Ok(L::wrap_template(Box::new(SeparateTemplate::new( + Ok(L::Property::wrap_template(Box::new(SeparateTemplate::new( separator, contents, )))) }); @@ -1671,7 +1632,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun suffix.format(formatter)?; Ok(()) }); - Ok(L::wrap_template(Box::new(template))) + Ok(L::Property::wrap_template(Box::new(template))) }); map.insert("config", |language, _diagnostics, _build_ctx, function| { // Dynamic lookup can be implemented if needed. The name is literal @@ -1689,7 +1650,7 @@ fn builtin_functions<'a, L: TemplateLanguage<'a> + ?Sized>() -> TemplateBuildFun .with_source(err) })?; // .decorated("", "") to trim leading/trailing whitespace - Ok(L::wrap_config_value( + Ok(L::Property::wrap_config_value( Literal(value.decorated("", "")).into_dyn(), )) }); @@ -1783,15 +1744,15 @@ pub fn build_expression<'a, L: TemplateLanguage<'a> + ?Sized>( } } ExpressionKind::Boolean(value) => { - let property = L::wrap_boolean(Literal(*value).into_dyn()); + let property = L::Property::wrap_boolean(Literal(*value).into_dyn()); Ok(Expression::unlabeled(property)) } ExpressionKind::Integer(value) => { - let property = L::wrap_integer(Literal(*value).into_dyn()); + let property = L::Property::wrap_integer(Literal(*value).into_dyn()); Ok(Expression::unlabeled(property)) } ExpressionKind::String(value) => { - let property = L::wrap_string(Literal(value.clone()).into_dyn()); + let property = L::Property::wrap_string(Literal(value.clone()).into_dyn()); Ok(Expression::unlabeled(property)) } ExpressionKind::Unary(op, arg_node) => { @@ -1815,7 +1776,7 @@ pub fn build_expression<'a, L: TemplateLanguage<'a> + ?Sized>( .iter() .map(|node| expect_template_expression(language, diagnostics, build_ctx, node)) .try_collect()?; - let property = L::wrap_template(Box::new(ConcatTemplate(templates))); + let property = L::Property::wrap_template(Box::new(ConcatTemplate(templates))); Ok(Expression::unlabeled(property)) } ExpressionKind::FunctionCall(function) => { @@ -1853,7 +1814,7 @@ pub fn build_expression<'a, L: TemplateLanguage<'a> + ?Sized>( /// Builds template evaluation tree from AST nodes, with fresh build context. /// /// `wrap_self` specifies the type of the top-level property, which should be -/// one of the `L::wrap_*()` functions. +/// one of the `L::Property::wrap_*()` functions. pub fn build<'a, C: Clone + 'a, L: TemplateLanguage<'a> + ?Sized>( language: &L, diagnostics: &mut TemplateDiagnostics, @@ -2017,12 +1978,12 @@ mod tests { use crate::formatter::ColorFormatter; use crate::generic_templater::GenericTemplateLanguage; - type L = GenericTemplateLanguage<'static, ()>; - type TestTemplatePropertyKind = >::Property; + type TestTemplateLanguage = GenericTemplateLanguage<'static, ()>; + type P = >::Property; /// Helper to set up template evaluation environment. struct TestTemplateEnv { - language: L, + language: TestTemplateLanguage, aliases_map: TemplateAliasesMap, color_rules: Vec<(Vec, formatter::Style)>, } @@ -2035,7 +1996,7 @@ mod tests { fn with_config(config: StackedConfig) -> Self { let settings = UserSettings::from_config(config).unwrap(); TestTemplateEnv { - language: L::new(&settings), + language: TestTemplateLanguage::new(&settings), aliases_map: TemplateAliasesMap::new(), color_rules: Vec::new(), } @@ -2045,7 +2006,7 @@ mod tests { impl TestTemplateEnv { fn add_keyword(&mut self, name: &'static str, build: F) where - F: Fn() -> TestTemplatePropertyKind + 'static, + F: Fn() -> P + 'static, { self.language.add_keyword(name, move |_| Ok(build())); } @@ -2069,7 +2030,7 @@ mod tests { &mut TemplateDiagnostics::new(), template, &self.aliases_map, - L::wrap_self, + P::wrap_self, ) } @@ -2117,9 +2078,9 @@ mod tests { #[test] fn test_parsed_tree() { let mut env = TestTemplateEnv::new(); - env.add_keyword("divergent", || L::wrap_boolean(literal(false))); - env.add_keyword("empty", || L::wrap_boolean(literal(true))); - env.add_keyword("hello", || L::wrap_string(literal("Hello".to_owned()))); + env.add_keyword("divergent", || P::wrap_boolean(literal(false))); + env.add_keyword("empty", || P::wrap_boolean(literal(true))); + env.add_keyword("hello", || P::wrap_string(literal("Hello".to_owned()))); // Empty insta::assert_snapshot!(env.render_ok(r#" "#), @""); @@ -2146,8 +2107,8 @@ mod tests { #[test] fn test_parse_error() { let mut env = TestTemplateEnv::new(); - env.add_keyword("description", || L::wrap_string(literal("".to_owned()))); - env.add_keyword("empty", || L::wrap_boolean(literal(true))); + env.add_keyword("description", || P::wrap_string(literal("".to_owned()))); + env.add_keyword("empty", || P::wrap_boolean(literal(true))); insta::assert_snapshot!(env.parse_err(r#"description ()"#), @r" --> 1:13 @@ -2391,7 +2352,7 @@ mod tests { #[test] fn test_self_keyword() { let mut env = TestTemplateEnv::new(); - env.add_keyword("say_hello", || L::wrap_string(literal("Hello".to_owned()))); + env.add_keyword("say_hello", || P::wrap_string(literal("Hello".to_owned()))); insta::assert_snapshot!(env.render_ok(r#"self.say_hello()"#), @"Hello"); insta::assert_snapshot!(env.parse_err(r#"self"#), @r" @@ -2412,9 +2373,9 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"if("a", true, false)"#), @"true"); env.add_keyword("sl0", || { - L::wrap_string_list(literal::>(vec![])) + P::wrap_string_list(literal::>(vec![])) }); - env.add_keyword("sl1", || L::wrap_string_list(literal(vec!["".to_owned()]))); + env.add_keyword("sl1", || P::wrap_string_list(literal(vec!["".to_owned()]))); insta::assert_snapshot!(env.render_ok(r#"if(sl0, true, false)"#), @"false"); insta::assert_snapshot!(env.render_ok(r#"if(sl1, true, false)"#), @"true"); @@ -2429,8 +2390,8 @@ mod tests { "); // Optional integer can be converted to boolean, and Some(0) is truthy. - env.add_keyword("none_i64", || L::wrap_integer_opt(literal(None))); - env.add_keyword("some_i64", || L::wrap_integer_opt(literal(Some(0)))); + env.add_keyword("none_i64", || P::wrap_integer_opt(literal(None))); + env.add_keyword("some_i64", || P::wrap_integer_opt(literal(Some(0)))); insta::assert_snapshot!(env.render_ok(r#"if(none_i64, true, false)"#), @"false"); insta::assert_snapshot!(env.render_ok(r#"if(some_i64, true, false)"#), @"true"); @@ -2452,10 +2413,10 @@ mod tests { "); env.add_keyword("empty_email", || { - L::wrap_email(literal(Email("".to_owned()))) + P::wrap_email(literal(Email("".to_owned()))) }); env.add_keyword("nonempty_email", || { - L::wrap_email(literal(Email("local@domain".to_owned()))) + P::wrap_email(literal(Email("local@domain".to_owned()))) }); insta::assert_snapshot!(env.render_ok(r#"if(empty_email, true, false)"#), @"false"); insta::assert_snapshot!(env.render_ok(r#"if(nonempty_email, true, false)"#), @"true"); @@ -2464,9 +2425,9 @@ mod tests { #[test] fn test_arithmetic_operation() { let mut env = TestTemplateEnv::new(); - env.add_keyword("none_i64", || L::wrap_integer_opt(literal(None))); - env.add_keyword("some_i64", || L::wrap_integer_opt(literal(Some(1)))); - env.add_keyword("i64_min", || L::wrap_integer(literal(i64::MIN))); + env.add_keyword("none_i64", || P::wrap_integer_opt(literal(None))); + env.add_keyword("some_i64", || P::wrap_integer_opt(literal(Some(1)))); + env.add_keyword("i64_min", || P::wrap_integer(literal(i64::MIN))); insta::assert_snapshot!(env.render_ok(r#"-1"#), @"-1"); insta::assert_snapshot!(env.render_ok(r#"--2"#), @"2"); @@ -2501,10 +2462,10 @@ mod tests { fn test_logical_operation() { let mut env = TestTemplateEnv::new(); env.add_keyword("email1", || { - L::wrap_email(literal(Email("local-1@domain".to_owned()))) + P::wrap_email(literal(Email("local-1@domain".to_owned()))) }); env.add_keyword("email2", || { - L::wrap_email(literal(Email("local-2@domain".to_owned()))) + P::wrap_email(literal(Email("local-2@domain".to_owned()))) }); insta::assert_snapshot!(env.render_ok(r#"!false"#), @"true"); @@ -2533,7 +2494,7 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#" "" || "a".lines() "#), @"true"); // Short-circuiting - env.add_keyword("bad_bool", || L::wrap_boolean(new_error_property("Bad"))); + env.add_keyword("bad_bool", || P::wrap_boolean(new_error_property("Bad"))); insta::assert_snapshot!(env.render_ok(r#"false && bad_bool"#), @"false"); insta::assert_snapshot!(env.render_ok(r#"true && bad_bool"#), @""); insta::assert_snapshot!(env.render_ok(r#"false || bad_bool"#), @""); @@ -2543,8 +2504,8 @@ mod tests { #[test] fn test_list_method() { let mut env = TestTemplateEnv::new(); - env.add_keyword("empty", || L::wrap_boolean(literal(true))); - env.add_keyword("sep", || L::wrap_string(literal("sep".to_owned()))); + env.add_keyword("empty", || P::wrap_boolean(literal(true))); + env.add_keyword("sep", || P::wrap_string(literal("sep".to_owned()))); insta::assert_snapshot!(env.render_ok(r#""".lines().len()"#), @"0"); insta::assert_snapshot!(env.render_ok(r#""a\nb\nc".lines().len()"#), @"3"); @@ -2660,9 +2621,9 @@ mod tests { fn test_string_method() { let mut env = TestTemplateEnv::new(); env.add_keyword("description", || { - L::wrap_string(literal("description 1".to_owned())) + P::wrap_string(literal("description 1".to_owned())) }); - env.add_keyword("bad_string", || L::wrap_string(new_error_property("Bad"))); + env.add_keyword("bad_string", || P::wrap_string(new_error_property("Bad"))); insta::assert_snapshot!(env.render_ok(r#""".len()"#), @"0"); insta::assert_snapshot!(env.render_ok(r#""foo".len()"#), @"3"); @@ -2757,16 +2718,16 @@ mod tests { fn test_config_value_method() { let mut env = TestTemplateEnv::new(); env.add_keyword("boolean", || { - L::wrap_config_value(literal(ConfigValue::from(true))) + P::wrap_config_value(literal(ConfigValue::from(true))) }); env.add_keyword("integer", || { - L::wrap_config_value(literal(ConfigValue::from(42))) + P::wrap_config_value(literal(ConfigValue::from(42))) }); env.add_keyword("string", || { - L::wrap_config_value(literal(ConfigValue::from("foo"))) + P::wrap_config_value(literal(ConfigValue::from("foo"))) }); env.add_keyword("string_list", || { - L::wrap_config_value(literal(ConfigValue::from_iter(["foo", "bar"]))) + P::wrap_config_value(literal(ConfigValue::from_iter(["foo", "bar"]))) }); insta::assert_snapshot!(env.render_ok("boolean"), @"true"); @@ -2798,7 +2759,7 @@ mod tests { let mut env = TestTemplateEnv::new(); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature("Test User", "test.user@example.com"))) + P::wrap_signature(literal(new_signature("Test User", "test.user@example.com"))) }); insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User "); insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @"Test User"); @@ -2806,7 +2767,7 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature( + P::wrap_signature(literal(new_signature( "Another Test User", "test.user@example.com", ))) @@ -2817,7 +2778,7 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature( + P::wrap_signature(literal(new_signature( "Test User", "test.user@invalid@example.com", ))) @@ -2828,14 +2789,14 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature("Test User", "test.user"))) + P::wrap_signature(literal(new_signature("Test User", "test.user"))) }); insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User "); insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"test.user"); insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature( + P::wrap_signature(literal(new_signature( "Test User", "test.user+tag@example.com", ))) @@ -2845,14 +2806,14 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user+tag"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature("Test User", "x@y"))) + P::wrap_signature(literal(new_signature("Test User", "x@y"))) }); insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User "); insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"x@y"); insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"x"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature("", "test.user@example.com"))) + P::wrap_signature(literal(new_signature("", "test.user@example.com"))) }); insta::assert_snapshot!(env.render_ok(r#"author"#), @""); insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @""); @@ -2860,7 +2821,7 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature("Test User", ""))) + P::wrap_signature(literal(new_signature("Test User", ""))) }); insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User"); insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @"Test User"); @@ -2868,7 +2829,7 @@ mod tests { insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @""); env.add_keyword("author", || { - L::wrap_signature(literal(new_signature("", ""))) + P::wrap_signature(literal(new_signature("", ""))) }); insta::assert_snapshot!(env.render_ok(r#"author"#), @""); insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @""); @@ -2880,19 +2841,19 @@ mod tests { fn test_size_hint_method() { let mut env = TestTemplateEnv::new(); - env.add_keyword("unbounded", || L::wrap_size_hint(literal((5, None)))); + env.add_keyword("unbounded", || P::wrap_size_hint(literal((5, None)))); insta::assert_snapshot!(env.render_ok(r#"unbounded.lower()"#), @"5"); insta::assert_snapshot!(env.render_ok(r#"unbounded.upper()"#), @""); insta::assert_snapshot!(env.render_ok(r#"unbounded.exact()"#), @""); insta::assert_snapshot!(env.render_ok(r#"unbounded.zero()"#), @"false"); - env.add_keyword("bounded", || L::wrap_size_hint(literal((0, Some(10))))); + env.add_keyword("bounded", || P::wrap_size_hint(literal((0, Some(10))))); insta::assert_snapshot!(env.render_ok(r#"bounded.lower()"#), @"0"); insta::assert_snapshot!(env.render_ok(r#"bounded.upper()"#), @"10"); insta::assert_snapshot!(env.render_ok(r#"bounded.exact()"#), @""); insta::assert_snapshot!(env.render_ok(r#"bounded.zero()"#), @"false"); - env.add_keyword("zero", || L::wrap_size_hint(literal((0, Some(0))))); + env.add_keyword("zero", || P::wrap_size_hint(literal((0, Some(0))))); insta::assert_snapshot!(env.render_ok(r#"zero.lower()"#), @"0"); insta::assert_snapshot!(env.render_ok(r#"zero.upper()"#), @"0"); insta::assert_snapshot!(env.render_ok(r#"zero.exact()"#), @"0"); @@ -2902,7 +2863,7 @@ mod tests { #[test] fn test_timestamp_method() { let mut env = TestTemplateEnv::new(); - env.add_keyword("t0", || L::wrap_timestamp(literal(new_timestamp(0, 0)))); + env.add_keyword("t0", || P::wrap_timestamp(literal(new_timestamp(0, 0)))); insta::assert_snapshot!( env.render_ok(r#"t0.format("%Y%m%d %H:%M:%S")"#), @@ -3098,7 +3059,7 @@ mod tests { #[test] fn test_pad_function() { let mut env = TestTemplateEnv::new(); - env.add_keyword("bad_string", || L::wrap_string(new_error_property("Bad"))); + env.add_keyword("bad_string", || P::wrap_string(new_error_property("Bad"))); env.add_color("red", crossterm::style::Color::Red); env.add_color("cyan", crossterm::style::Color::DarkCyan); @@ -3153,7 +3114,7 @@ mod tests { #[test] fn test_label_function() { let mut env = TestTemplateEnv::new(); - env.add_keyword("empty", || L::wrap_boolean(literal(true))); + env.add_keyword("empty", || P::wrap_boolean(literal(true))); env.add_color("error", crossterm::style::Color::DarkRed); env.add_color("warning", crossterm::style::Color::DarkYellow); @@ -3227,10 +3188,10 @@ mod tests { #[test] fn test_coalesce_function() { let mut env = TestTemplateEnv::new(); - env.add_keyword("bad_string", || L::wrap_string(new_error_property("Bad"))); - env.add_keyword("empty_string", || L::wrap_string(literal("".to_owned()))); + env.add_keyword("bad_string", || P::wrap_string(new_error_property("Bad"))); + env.add_keyword("empty_string", || P::wrap_string(literal("".to_owned()))); env.add_keyword("non_empty_string", || { - L::wrap_string(literal("a".to_owned())) + P::wrap_string(literal("a".to_owned())) }); insta::assert_snapshot!(env.render_ok(r#"coalesce()"#), @""); @@ -3251,8 +3212,8 @@ mod tests { #[test] fn test_concat_function() { let mut env = TestTemplateEnv::new(); - env.add_keyword("empty", || L::wrap_boolean(literal(true))); - env.add_keyword("hidden", || L::wrap_boolean(literal(false))); + env.add_keyword("empty", || P::wrap_boolean(literal(true))); + env.add_keyword("hidden", || P::wrap_boolean(literal(false))); env.add_color("empty", crossterm::style::Color::DarkGreen); env.add_color("error", crossterm::style::Color::DarkRed); env.add_color("warning", crossterm::style::Color::DarkYellow); @@ -3269,9 +3230,9 @@ mod tests { #[test] fn test_separate_function() { let mut env = TestTemplateEnv::new(); - env.add_keyword("description", || L::wrap_string(literal("".to_owned()))); - env.add_keyword("empty", || L::wrap_boolean(literal(true))); - env.add_keyword("hidden", || L::wrap_boolean(literal(false))); + env.add_keyword("description", || P::wrap_string(literal("".to_owned()))); + env.add_keyword("empty", || P::wrap_boolean(literal(true))); + env.add_keyword("hidden", || P::wrap_boolean(literal(false))); env.add_color("empty", crossterm::style::Color::DarkGreen); env.add_color("error", crossterm::style::Color::DarkRed); env.add_color("warning", crossterm::style::Color::DarkYellow); @@ -3325,10 +3286,10 @@ mod tests { #[test] fn test_surround_function() { let mut env = TestTemplateEnv::new(); - env.add_keyword("lt", || L::wrap_string(literal("<".to_owned()))); - env.add_keyword("gt", || L::wrap_string(literal(">".to_owned()))); - env.add_keyword("content", || L::wrap_string(literal("content".to_owned()))); - env.add_keyword("empty_content", || L::wrap_string(literal("".to_owned()))); + env.add_keyword("lt", || P::wrap_string(literal("<".to_owned()))); + env.add_keyword("gt", || P::wrap_string(literal(">".to_owned()))); + env.add_keyword("content", || P::wrap_string(literal("content".to_owned()))); + env.add_keyword("empty_content", || P::wrap_string(literal("".to_owned()))); env.add_color("error", crossterm::style::Color::DarkRed); env.add_color("paren", crossterm::style::Color::Cyan);