diff --git a/espanso-config/src/matches/group/loader/yaml/mod.rs b/espanso-config/src/matches/group/loader/yaml/mod.rs index 785cea3..1559fda 100644 --- a/espanso-config/src/matches/group/loader/yaml/mod.rs +++ b/espanso-config/src/matches/group/loader/yaml/mod.rs @@ -316,6 +316,7 @@ pub fn try_convert_into_variable( params: convert_params(yaml_var.params)?, id: next_id(), inject_vars: !use_compatibility_mode && yaml_var.inject_vars.unwrap_or(true), + depends_on: yaml_var.depends_on, }, Vec::new(), )) @@ -745,6 +746,52 @@ mod tests { ) } + #[test] + fn vars_inject_vars_and_depends_on() { + let vars = vec![ + Variable { + name: "var1".to_string(), + var_type: "test".to_string(), + depends_on: vec!["test".to_owned()], + ..Default::default() + }, + Variable { + name: "var2".to_string(), + var_type: "test".to_string(), + inject_vars: false, + ..Default::default() + }, + ]; + assert_eq!( + create_match( + r#" + trigger: "Hello" + replace: "world" + vars: + - name: var1 + type: test + depends_on: ["test"] + - name: var2 + type: "test" + inject_vars: false + "# + ) + .unwrap(), + Match { + cause: MatchCause::Trigger(TriggerCause { + triggers: vec!["Hello".to_string()], + ..Default::default() + }), + effect: MatchEffect::Text(TextEffect { + replace: "world".to_string(), + vars, + ..Default::default() + }), + ..Default::default() + } + ) + } + #[test] fn vars_no_params_maps_correctly() { let vars = vec![Variable { diff --git a/espanso-config/src/matches/group/loader/yaml/parse.rs b/espanso-config/src/matches/group/loader/yaml/parse.rs index 52ca447..50c1463 100644 --- a/espanso-config/src/matches/group/loader/yaml/parse.rs +++ b/espanso-config/src/matches/group/loader/yaml/parse.rs @@ -128,6 +128,9 @@ pub struct YAMLVariable { #[serde(default)] pub inject_vars: Option, + + #[serde(default)] + pub depends_on: Vec, } fn default_params() -> Mapping { diff --git a/espanso-config/src/matches/mod.rs b/espanso-config/src/matches/mod.rs index 5d74bdd..8d2a5bb 100644 --- a/espanso-config/src/matches/mod.rs +++ b/espanso-config/src/matches/mod.rs @@ -206,6 +206,7 @@ pub struct Variable { pub var_type: String, pub params: Params, pub inject_vars: bool, + pub depends_on: Vec, } impl Default for Variable { @@ -216,6 +217,7 @@ impl Default for Variable { var_type: String::new(), params: Params::new(), inject_vars: true, + depends_on: Vec::new(), } } }