Skip to content

Commit

Permalink
fix: Don't panic for different/missing delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
DropDemBits committed Jul 8, 2023
1 parent 2eb5064 commit 5fddf3e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion crates/ide-assists/src/handlers/generate_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};
})
Expand Down Expand Up @@ -102,6 +102,38 @@ mod m {
);
}

#[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(
Expand Down

0 comments on commit 5fddf3e

Please sign in to comment.