// ```
// ->
// ```
-// type Type = (u8, u8, u8);
+// type ${0:Type} = (u8, u8, u8);
//
// struct S {
-// field: Type,
+// field: ${0:Type},
// }
// ```
pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
target,
|builder| {
builder.edit_file(ctx.frange.file_id);
- // FIXME: add snippet support
- builder.replace(target, "Type");
- builder.insert(insert, format!("type Type = {};\n\n", node));
+ match ctx.config.snippet_cap {
+ Some(cap) => {
+ builder.replace_snippet(cap, target, "${0:Type}");
+ builder.insert_snippet(
+ cap,
+ insert,
+ format!("type ${{0:Type}} = {};\n\n", node),
+ );
+ }
+ None => {
+ builder.replace(target, "Type");
+ builder.insert(insert, format!("type Type = {};\n\n", node));
+ }
+ }
},
)
}
}
",
r#"
-type Type = u8;
+type ${0:Type} = u8;
struct S {
- field: Type,
+ field: ${0:Type},
}
"#,
);
r#"
fn generic<T>() {}
-type Type = ();
+type ${0:Type} = ();
fn f() {
- generic::<Type>();
+ generic::<${0:Type}>();
}
"#,
);
",
r#"
struct Vec<T> {}
-type Type = Vec<u8>;
+type ${0:Type} = Vec<u8>;
struct S {
- v: Vec<Vec<Type>>,
+ v: Vec<Vec<${0:Type}>>,
}
"#,
);
}
",
r#"
-type Type = u8;
+type ${0:Type} = u8;
struct S {
- field: (Type,),
+ field: (${0:Type},),
}
"#,
);