use ryo_fuzzy_parser::TaggedEnumSchema;
pub static INTENT_TYPES: &[&str] = &[
"RenameIdent",
"ChangeVisibility",
"MoveItem",
"ExtractTrait",
"InlineTrait",
"RemoveMod",
"CreateMod",
"AddField",
"RemoveField",
"AddDerive",
"RemoveDerive",
"AddEnum",
"AddVariant",
"RemoveVariant",
"AddMatchArm",
"RemoveMatchArm",
"ReplaceMatchArm",
"AddStructLiteralField",
"RemoveStructLiteralField",
"RemoveStruct",
"RemoveEnum",
"DuplicateFunction",
"DuplicateStruct",
"DuplicateEnum",
"DuplicateModTree",
"AddConst",
"AddTypeAlias",
"AddSpec",
"AddMethod",
"RemoveMethod",
"RemoveConst",
"RemoveTypeAlias",
"RemoveUse",
"RemoveTrait",
"RemoveImpl",
"AddItem",
"RemoveItem",
"AddCode",
"OrganizeImports",
"MergeImplBlocks",
"LoopToIterator",
"UnwrapToQuestion",
"IntroduceVariable",
"GenerateBuilder",
"ReplaceExpr",
"RemoveStatement",
"InsertStatement",
"ReplaceStatement",
"AssignOp",
"BoolSimplify",
"CloneOnCopy",
"CollapsibleIf",
"ComparisonToMethod",
"RedundantClosure",
"ManualMap",
"MatchToIfLet",
"Custom",
#[cfg(feature = "wasm-plugin")]
"Plugin",
];
pub fn get_intent_fields(tag: &str) -> Option<&'static [&'static str]> {
match tag {
"RenameIdent" => Some(&["from", "to", "kind"]),
"ChangeVisibility" => Some(&["target", "to"]),
"MoveItem" => Some(&["target", "to_module"]),
"ExtractTrait" => Some(&["from_impl", "trait_name", "methods"]),
"InlineTrait" => Some(&["trait_name", "struct_name", "remove_trait"]),
"RemoveMod" => Some(&["parent_mod", "mod_name"]),
"CreateMod" => Some(&["parent_mod", "mod_name", "content", "is_pub"]),
"AddField" => Some(&["struct_name", "field_name", "field_type", "is_pub"]),
"RemoveField" => Some(&["struct_name", "field_name"]),
"AddDerive" => Some(&["target", "derives"]),
"RemoveDerive" => Some(&["target", "derives"]),
"AddEnum" => Some(&["name", "variants", "is_pub", "derives"]),
"AddVariant" => Some(&["enum_name", "variant_name", "variant_type"]),
"RemoveVariant" => Some(&["enum_name", "variant_name"]),
"AddMatchArm" => Some(&[
"symbol_path",
"file_path",
"function_name",
"enum_name",
"pattern",
"body",
]),
"RemoveMatchArm" => Some(&[
"symbol_path",
"file_path",
"function_name",
"enum_name",
"pattern",
]),
"ReplaceMatchArm" => Some(&[
"symbol_path",
"file_path",
"function_name",
"enum_name",
"old_pattern",
"new_pattern",
"new_body",
]),
"AddStructLiteralField" => Some(&["struct_name", "field_name", "value"]),
"RemoveStructLiteralField" => Some(&["struct_name", "field_name"]),
"RemoveStruct" => Some(&["name"]),
"RemoveEnum" => Some(&["name"]),
"DuplicateFunction" => Some(&["from", "to"]),
"DuplicateStruct" => Some(&["from", "to", "include_impls"]),
"DuplicateEnum" => Some(&["from", "to", "include_impls"]),
"DuplicateModTree" => Some(&["from", "to"]),
"AddConst" => Some(&["name", "ty", "value", "is_pub"]),
"AddTypeAlias" => Some(&["name", "ty", "is_pub"]),
"AddSpec" => Some(&[
"target_type",
"group",
"alias_name",
"relations",
"module_path",
"file_path",
]),
"AddMethod" => Some(&[
"impl_target",
"method_name",
"params",
"return_type",
"body",
"is_pub",
"self_param",
]),
"RemoveMethod" => Some(&["impl_target", "method_name"]),
"RemoveConst" => Some(&["name"]),
"RemoveTypeAlias" => Some(&["name"]),
"RemoveUse" => Some(&["path"]),
"RemoveTrait" => Some(&["name"]),
"RemoveImpl" => Some(&["self_ty", "trait_name"]),
"AddItem" => Some(&["location", "content", "item_kind"]),
"RemoveItem" => Some(&["target", "item_kind"]),
"AddCode" => Some(&["parent", "parent_ref", "code"]),
"OrganizeImports" => Some(&["target_mod", "deduplicate", "merge_groups"]),
"MergeImplBlocks" => Some(&["target_mod", "target_type", "inherent_only"]),
"LoopToIterator" => Some(&["target_mod", "target_var"]),
"UnwrapToQuestion" => Some(&["target_mod", "target_fn", "include_expect"]),
"IntroduceVariable" => Some(&["target_mod", "target_fn", "expr", "var_name"]),
"GenerateBuilder" => Some(&[
"struct_name",
"struct_id",
"target_mod",
"fields",
"add_builder_method",
]),
"ReplaceExpr" => Some(&[
"target_mod",
"target_fn",
"old_expr",
"new_expr",
"replace_all",
"symbol_path",
]),
"RemoveStatement" => Some(&[
"target_mod",
"target_fn",
"pattern",
"remove_all",
"symbol_path",
]),
"InsertStatement" => Some(&[
"target_mod",
"target_fn",
"stmt",
"position",
"reference_pattern",
"symbol_path",
]),
"ReplaceStatement" => Some(&[
"target_mod",
"target_fn",
"old_stmt",
"new_stmt",
"symbol_path",
]),
"AssignOp" => Some(&["target_mod", "target_fn"]),
"BoolSimplify" => Some(&["target_mod"]),
"CloneOnCopy" => Some(&["target_mod"]),
"CollapsibleIf" => Some(&["target_mod"]),
"ComparisonToMethod" => Some(&["target_mod"]),
"RedundantClosure" => Some(&["target_mod"]),
"ManualMap" => Some(&["target_mod"]),
"MatchToIfLet" => Some(&["target_mod"]),
"Custom" => Some(&["description", "examples"]),
#[cfg(feature = "wasm-plugin")]
"Plugin" => Some(&["name", "file_patterns"]),
_ => None,
}
}
pub static GOAL_FIELDS: &[&str] = &[
"query",
"intents",
"scope",
"constraints",
"conflict_strategy",
"confidence",
];
pub fn intent_schema() -> TaggedEnumSchema<fn(&str) -> Option<&'static [&'static str]>> {
TaggedEnumSchema::new("type", INTENT_TYPES, get_intent_fields)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_intent_types_coverage() {
for &type_name in INTENT_TYPES {
assert!(
get_intent_fields(type_name).is_some(),
"Missing field definition for: {}",
type_name
);
}
}
#[test]
fn test_schema_creation() {
let schema = intent_schema();
assert_eq!(schema.tag_field, "type");
assert!(schema.is_valid_tag("AddDerive"));
assert!(!schema.is_valid_tag("InvalidType"));
}
}