fix: ADD SWITCHER keyword - use register_custom_syntax instead of register_fn

The compiler outputs ADD_SWITCHER "x" as "y" format but the keyword
was registered as a plain Rhai function expecting add_switcher(x, y).
Changed to register_custom_syntax matching the output format, consistent
with ADD_SUGGESTION and CLEAR SWITCHERS patterns.

Fixes #495
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-25 13:15:24 +00:00
parent 28c48eeabf
commit 867c5c5be4

View file

@ -84,23 +84,32 @@ pub fn clear_switchers_keyword(
} }
pub fn add_switcher_keyword( pub fn add_switcher_keyword(
state: Arc<AppState>, state: Arc<AppState>,
user_session: UserSession, user_session: UserSession,
engine: &mut Engine, engine: &mut Engine,
) { ) {
let cache = state.cache.clone(); let cache = state.cache.clone();
let user_session_clone = user_session.clone(); let user_session_clone = user_session.clone();
engine engine
.register_fn("add_switcher", move |switcher_id: &str, button_text: &str| { .register_custom_syntax(
let result = add_switcher( ["ADD_SWITCHER", "$expr$", "as", "$expr$"],
cache.as_ref(), true,
&user_session_clone, move |context, inputs| {
switcher_id, let switcher_id = context.eval_expression_tree(&inputs[0])?.to_string();
button_text, let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
);
result.map_err(|e| e.to_string()) add_switcher(
}); cache.as_ref(),
&user_session_clone,
&switcher_id,
&button_text,
)?;
Ok(Dynamic::UNIT)
},
)
.expect("valid syntax registration");
} }
fn add_switcher( fn add_switcher(