From 8f936c557162d66a451f10481ff726a37b27302e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Jun 2021 19:25:09 +0200 Subject: Add builtin derives to attribute completion fixtures --- .../src/completions/attribute/derive.rs | 74 ++++++++++++++++++++-- 1 file changed, 67 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs index 7b3133e53..c59add6c5 100644 --- a/crates/ide_completion/src/completions/attribute/derive.rs +++ b/crates/ide_completion/src/completions/attribute/derive.rs @@ -83,7 +83,31 @@ mod tests { use crate::{test_utils::completion_list, CompletionKind}; fn check(ra_fixture: &str, expect: Expect) { - let actual = completion_list(ra_fixture, CompletionKind::Attribute); + let builtin_derives = r#" +#[rustc_builtin_macro] +pub macro Clone {} +#[rustc_builtin_macro] +pub macro Copy {} +#[rustc_builtin_macro] +pub macro Default {} +#[rustc_builtin_macro] +pub macro Debug {} +#[rustc_builtin_macro] +pub macro Hash {} +#[rustc_builtin_macro] +pub macro PartialEq {} +#[rustc_builtin_macro] +pub macro Eq {} +#[rustc_builtin_macro] +pub macro PartialOrd {} +#[rustc_builtin_macro] +pub macro Ord {} + +"#; + let actual = completion_list( + &format!("{} {}", builtin_derives, ra_fixture), + CompletionKind::Attribute, + ); expect.assert_eq(&actual); } @@ -94,19 +118,55 @@ mod tests { #[test] fn empty_derive() { - // FIXME: Add build-in derives to fixture. - check(r#"#[derive($0)] struct Test;"#, expect![[r#""#]]); + check( + r#"#[derive($0)] struct Test;"#, + expect![[r#" + at PartialEq + at Default + at PartialEq, Eq + at PartialEq, Eq, PartialOrd, Ord + at Clone, Copy + at Debug + at Clone + at Hash + at PartialEq, PartialOrd + "#]], + ); } #[test] fn derive_with_input() { - // FIXME: Add build-in derives to fixture. - check(r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, expect![[r#""#]]) + check( + r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, + expect![[r#" + at PartialEq + at Default + at Eq + at Eq, PartialOrd, Ord + at Clone, Copy + at Debug + at Clone + at Hash + at PartialOrd + "#]], + ) } #[test] fn derive_with_input2() { - // FIXME: Add build-in derives to fixture. - check(r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, expect![[r#""#]]) + check( + r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, + expect![[r#" + at PartialEq + at Default + at Eq + at Eq, PartialOrd, Ord + at Clone, Copy + at Debug + at Clone + at Hash + at PartialOrd + "#]], + ) } } -- cgit v1.2.3 From a92ed1eef4a5804c474221d1088dafb5d45f1378 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Jun 2021 19:27:06 +0200 Subject: Don't complete already used derive attributes --- .../src/completions/attribute/derive.rs | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'crates') diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs index c59add6c5..20bbbba46 100644 --- a/crates/ide_completion/src/completions/attribute/derive.rs +++ b/crates/ide_completion/src/completions/attribute/derive.rs @@ -31,6 +31,8 @@ pub(super) fn complete_derive( let lookup = components.join(", "); let label = components.iter().rev().join(", "); (label, Some(lookup)) + } else if existing_derives.contains(&derive) { + continue; } else { (derive, None) }; @@ -139,16 +141,15 @@ pub macro Ord {} check( r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, expect![[r#" - at PartialEq - at Default - at Eq - at Eq, PartialOrd, Ord - at Clone, Copy - at Debug - at Clone - at Hash - at PartialOrd - "#]], + at Default + at Eq + at Eq, PartialOrd, Ord + at Clone, Copy + at Debug + at Clone + at Hash + at PartialOrd + "#]], ) } @@ -157,16 +158,15 @@ pub macro Ord {} check( r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, expect![[r#" - at PartialEq - at Default - at Eq - at Eq, PartialOrd, Ord - at Clone, Copy - at Debug - at Clone - at Hash - at PartialOrd - "#]], + at Default + at Eq + at Eq, PartialOrd, Ord + at Clone, Copy + at Debug + at Clone + at Hash + at PartialOrd + "#]], ) } } -- cgit v1.2.3