fix: Don't panic for different/missing delimiters
This commit is contained in:
parent
2eb506462e
commit
5fddf3ef6d
@ -53,7 +53,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
|
||||
Some(tt) => {
|
||||
// Just move the cursor.
|
||||
let tt = edit.make_mut(tt);
|
||||
edit.add_tabstop_before_token(cap, tt.r_paren_token().unwrap());
|
||||
edit.add_tabstop_before_token(cap, tt.right_delimiter_token().unwrap());
|
||||
}
|
||||
};
|
||||
})
|
||||
@ -102,6 +102,38 @@ fn add_derive_existing() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_derive_existing_with_brackets() {
|
||||
check_assist(
|
||||
generate_derive,
|
||||
"
|
||||
#[derive[Clone]]
|
||||
struct Foo { a: i32$0, }
|
||||
",
|
||||
"
|
||||
#[derive[Clone$0]]
|
||||
struct Foo { a: i32, }
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_derive_existing_missing_delimiter() {
|
||||
// since `#[derive]` isn't a simple attr call (i.e. `#[derive()]`)
|
||||
// we don't consider it as a proper derive attr and generate a new
|
||||
// one instead
|
||||
check_assist(
|
||||
generate_derive,
|
||||
"
|
||||
#[derive]
|
||||
struct Foo { a: i32$0, }",
|
||||
"
|
||||
#[derive]
|
||||
#[derive($0)]
|
||||
struct Foo { a: i32, }",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_derive_new_with_doc_comment() {
|
||||
check_assist(
|
||||
|
Loading…
Reference in New Issue
Block a user