fix: Don't panic for different/missing delimiters

This commit is contained in:
DropDemBits 2023-07-08 13:43:30 -04:00
parent 2eb506462e
commit 5fddf3ef6d
No known key found for this signature in database
GPG Key ID: 7FE02A6C1EDFA075

View File

@ -53,7 +53,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
Some(tt) => { Some(tt) => {
// Just move the cursor. // Just move the cursor.
let tt = edit.make_mut(tt); 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] #[test]
fn add_derive_new_with_doc_comment() { fn add_derive_new_with_doc_comment() {
check_assist( check_assist(