From edd450abc988185686ea5e22191160f5c56d0df2 Mon Sep 17 00:00:00 2001 From: Hegui Dai Date: Tue, 25 Mar 2025 14:31:28 +0800 Subject: [PATCH 1/3] add more completion about "impl" --- .../src/completions/item_list.rs | 4 ++ .../ide-completion/src/completions/keyword.rs | 2 + crates/ide-completion/src/tests/expression.rs | 68 +++++++++++++------ crates/ide-completion/src/tests/item.rs | 2 + crates/ide-completion/src/tests/item_list.rs | 10 +++ crates/ide-completion/src/tests/special.rs | 12 +++- 6 files changed, 76 insertions(+), 22 deletions(-) diff --git a/crates/ide-completion/src/completions/item_list.rs b/crates/ide-completion/src/completions/item_list.rs index 4ae00ccd81..30ffeff261 100644 --- a/crates/ide-completion/src/completions/item_list.rs +++ b/crates/ide-completion/src/completions/item_list.rs @@ -114,6 +114,8 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option add_keyword("trait", "trait $1 {\n $0\n}"); if no_vis_qualifiers { add_keyword("impl", "impl $1 {\n $0\n}"); + add_keyword("impl for", "impl $1 for $2 {\n $0\n}"); + add_keyword("impl<> for <>", "impl<$4> $1 for $2<$3> {\n $0\n}"); } } @@ -144,6 +146,8 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option add_keyword("use", "use $0"); if no_vis_qualifiers { add_keyword("impl", "impl $1 {\n $0\n}"); + add_keyword("impl for", "impl $1 for $2 {\n $0\n}"); + add_keyword("impl<> for <>", "impl<$4> $1 for $2<$3> {\n $0\n}"); } } diff --git a/crates/ide-completion/src/completions/keyword.rs b/crates/ide-completion/src/completions/keyword.rs index 14b0d543ca..d0ba910d93 100644 --- a/crates/ide-completion/src/completions/keyword.rs +++ b/crates/ide-completion/src/completions/keyword.rs @@ -56,6 +56,8 @@ mod tests { kw extern kw fn kw impl + kw impl for + kw impl<> for <> kw trait "#]], ); diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index 22d42ba750..5314be3c7f 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -171,6 +171,8 @@ impl Unit { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -236,8 +238,8 @@ fn complete_in_block() { } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -249,6 +251,8 @@ fn complete_in_block() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -285,8 +289,8 @@ fn complete_after_if_expr() { } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -300,6 +304,8 @@ fn complete_after_if_expr() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -360,8 +366,8 @@ fn completes_in_loop_ctx() { check( r"fn my() { loop { $0 } }", expect![[r#" - fn my() fn() - bt u32 u32 + fn my() fn() + bt u32 u32 kw async kw break kw const @@ -375,6 +381,8 @@ fn completes_in_loop_ctx() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -946,8 +954,8 @@ fn else_completion_after_if() { fn foo() { if foo {} $0 } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -961,6 +969,8 @@ fn foo() { if foo {} $0 } kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -988,8 +998,8 @@ fn foo() { if foo {} $0 } fn foo() { if foo {} el$0 } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1003,6 +1013,8 @@ fn foo() { if foo {} el$0 } kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1080,8 +1092,8 @@ fn foo() { bar(if foo {} el$0) } fn foo() { if foo {} $0 let x = 92; } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1095,6 +1107,8 @@ fn foo() { if foo {} $0 let x = 92; } kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1122,8 +1136,8 @@ fn foo() { if foo {} $0 let x = 92; } fn foo() { if foo {} el$0 let x = 92; } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1137,6 +1151,8 @@ fn foo() { if foo {} el$0 let x = 92; } kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1164,8 +1180,8 @@ fn foo() { if foo {} el$0 let x = 92; } fn foo() { if foo {} el$0 { let x = 92; } } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1179,6 +1195,8 @@ fn foo() { if foo {} el$0 { let x = 92; } } kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1217,9 +1235,9 @@ fn main() { pub struct UnstableThisShouldNotBeListed; "#, expect![[r#" - fn main() fn() + fn main() fn() md std - bt u32 u32 + bt u32 u32 kw async kw const kw crate:: @@ -1231,6 +1249,8 @@ pub struct UnstableThisShouldNotBeListed; kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1285,6 +1305,8 @@ pub struct UnstableButWeAreOnNightlyAnyway; kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1529,6 +1551,8 @@ fn main() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1986,6 +2010,8 @@ fn bar() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -2044,9 +2070,9 @@ fn foo() { } "#, expect![[r#" - fn foo() fn() + fn foo() fn() md proc_macros - bt u32 u32 + bt u32 u32 kw async kw const kw crate:: @@ -2058,6 +2084,8 @@ fn foo() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop diff --git a/crates/ide-completion/src/tests/item.rs b/crates/ide-completion/src/tests/item.rs index be2c37d101..a2d2cf39c2 100644 --- a/crates/ide-completion/src/tests/item.rs +++ b/crates/ide-completion/src/tests/item.rs @@ -284,6 +284,8 @@ fn bar() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop diff --git a/crates/ide-completion/src/tests/item_list.rs b/crates/ide-completion/src/tests/item_list.rs index 841c42123a..ee77845588 100644 --- a/crates/ide-completion/src/tests/item_list.rs +++ b/crates/ide-completion/src/tests/item_list.rs @@ -16,6 +16,8 @@ fn in_mod_item_list() { kw extern kw fn kw impl + kw impl for + kw impl<> for <> kw mod kw pub kw pub(crate) @@ -50,6 +52,8 @@ fn in_source_file_item_list() { kw extern kw fn kw impl + kw impl for + kw impl<> for <> kw mod kw pub kw pub(crate) @@ -83,6 +87,8 @@ fn in_item_list_after_attr() { kw extern kw fn kw impl + kw impl for + kw impl<> for <> kw mod kw pub kw pub(crate) @@ -122,6 +128,8 @@ fn after_unsafe_token() { kw extern kw fn kw impl + kw impl for + kw impl<> for <> kw trait "#]], ); @@ -385,6 +393,8 @@ fn after_unit_struct() { kw extern kw fn kw impl + kw impl for + kw impl<> for <> kw mod kw pub kw pub(crate) diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs index 70caeac95b..ca579b8fc1 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -1008,6 +1008,8 @@ fn here_we_go() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1059,6 +1061,8 @@ fn here_we_go() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1184,6 +1188,8 @@ fn bar() { qu$0 } kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop @@ -1428,8 +1434,8 @@ fn foo() { "#, Some('_'), expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1441,6 +1447,8 @@ fn foo() { kw if kw if let kw impl + kw impl for + kw impl<> for <> kw let kw letm kw loop From 307cd68fc6136148602dd7f7d40b02be1966b66b Mon Sep 17 00:00:00 2001 From: Hegui Dai Date: Fri, 28 Mar 2025 18:25:32 +0800 Subject: [PATCH 2/3] move "impl<> for <>" and test about it --- crates/ide-completion/src/completions/item_list.rs | 2 -- crates/ide-completion/src/completions/keyword.rs | 1 - crates/ide-completion/src/tests/expression.rs | 14 -------------- crates/ide-completion/src/tests/item.rs | 1 - crates/ide-completion/src/tests/item_list.rs | 5 ----- crates/ide-completion/src/tests/special.rs | 4 ---- 6 files changed, 27 deletions(-) diff --git a/crates/ide-completion/src/completions/item_list.rs b/crates/ide-completion/src/completions/item_list.rs index 30ffeff261..58e7f584ed 100644 --- a/crates/ide-completion/src/completions/item_list.rs +++ b/crates/ide-completion/src/completions/item_list.rs @@ -115,7 +115,6 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option if no_vis_qualifiers { add_keyword("impl", "impl $1 {\n $0\n}"); add_keyword("impl for", "impl $1 for $2 {\n $0\n}"); - add_keyword("impl<> for <>", "impl<$4> $1 for $2<$3> {\n $0\n}"); } } @@ -147,7 +146,6 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option if no_vis_qualifiers { add_keyword("impl", "impl $1 {\n $0\n}"); add_keyword("impl for", "impl $1 for $2 {\n $0\n}"); - add_keyword("impl<> for <>", "impl<$4> $1 for $2<$3> {\n $0\n}"); } } diff --git a/crates/ide-completion/src/completions/keyword.rs b/crates/ide-completion/src/completions/keyword.rs index d0ba910d93..039742463c 100644 --- a/crates/ide-completion/src/completions/keyword.rs +++ b/crates/ide-completion/src/completions/keyword.rs @@ -57,7 +57,6 @@ mod tests { kw fn kw impl kw impl for - kw impl<> for <> kw trait "#]], ); diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index 5314be3c7f..46a725db67 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -172,7 +172,6 @@ impl Unit { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -252,7 +251,6 @@ fn complete_in_block() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -305,7 +303,6 @@ fn complete_after_if_expr() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -382,7 +379,6 @@ fn completes_in_loop_ctx() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -970,7 +966,6 @@ fn foo() { if foo {} $0 } kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1014,7 +1009,6 @@ fn foo() { if foo {} el$0 } kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1108,7 +1102,6 @@ fn foo() { if foo {} $0 let x = 92; } kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1152,7 +1145,6 @@ fn foo() { if foo {} el$0 let x = 92; } kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1196,7 +1188,6 @@ fn foo() { if foo {} el$0 { let x = 92; } } kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1250,7 +1241,6 @@ pub struct UnstableThisShouldNotBeListed; kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1306,7 +1296,6 @@ pub struct UnstableButWeAreOnNightlyAnyway; kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1552,7 +1541,6 @@ fn main() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -2011,7 +1999,6 @@ fn bar() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -2085,7 +2072,6 @@ fn foo() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop diff --git a/crates/ide-completion/src/tests/item.rs b/crates/ide-completion/src/tests/item.rs index a2d2cf39c2..55689034fb 100644 --- a/crates/ide-completion/src/tests/item.rs +++ b/crates/ide-completion/src/tests/item.rs @@ -285,7 +285,6 @@ fn bar() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop diff --git a/crates/ide-completion/src/tests/item_list.rs b/crates/ide-completion/src/tests/item_list.rs index ee77845588..fcdf10c856 100644 --- a/crates/ide-completion/src/tests/item_list.rs +++ b/crates/ide-completion/src/tests/item_list.rs @@ -17,7 +17,6 @@ fn in_mod_item_list() { kw fn kw impl kw impl for - kw impl<> for <> kw mod kw pub kw pub(crate) @@ -53,7 +52,6 @@ fn in_source_file_item_list() { kw fn kw impl kw impl for - kw impl<> for <> kw mod kw pub kw pub(crate) @@ -88,7 +86,6 @@ fn in_item_list_after_attr() { kw fn kw impl kw impl for - kw impl<> for <> kw mod kw pub kw pub(crate) @@ -129,7 +126,6 @@ fn after_unsafe_token() { kw fn kw impl kw impl for - kw impl<> for <> kw trait "#]], ); @@ -394,7 +390,6 @@ fn after_unit_struct() { kw fn kw impl kw impl for - kw impl<> for <> kw mod kw pub kw pub(crate) diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs index ca579b8fc1..347febce01 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -1009,7 +1009,6 @@ fn here_we_go() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1062,7 +1061,6 @@ fn here_we_go() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1189,7 +1187,6 @@ fn bar() { qu$0 } kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop @@ -1448,7 +1445,6 @@ fn foo() { kw if let kw impl kw impl for - kw impl<> for <> kw let kw letm kw loop From e3ec43319a15af6936bc2f3aa0a9afaac0190fc6 Mon Sep 17 00:00:00 2001 From: Hegui Dai Date: Fri, 28 Mar 2025 18:28:56 +0800 Subject: [PATCH 3/3] update test --- crates/ide-completion/src/tests/expression.rs | 40 +++++++++---------- crates/ide-completion/src/tests/special.rs | 4 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index 46a725db67..f3d957c2ed 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -237,8 +237,8 @@ fn complete_in_block() { } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -287,8 +287,8 @@ fn complete_after_if_expr() { } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -363,8 +363,8 @@ fn completes_in_loop_ctx() { check( r"fn my() { loop { $0 } }", expect![[r#" - fn my() fn() - bt u32 u32 + fn my() fn() + bt u32 u32 kw async kw break kw const @@ -950,8 +950,8 @@ fn else_completion_after_if() { fn foo() { if foo {} $0 } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -993,8 +993,8 @@ fn foo() { if foo {} $0 } fn foo() { if foo {} el$0 } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1086,8 +1086,8 @@ fn foo() { bar(if foo {} el$0) } fn foo() { if foo {} $0 let x = 92; } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1129,8 +1129,8 @@ fn foo() { if foo {} $0 let x = 92; } fn foo() { if foo {} el$0 let x = 92; } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1172,8 +1172,8 @@ fn foo() { if foo {} el$0 let x = 92; } fn foo() { if foo {} el$0 { let x = 92; } } "#, expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate:: @@ -1226,9 +1226,9 @@ fn main() { pub struct UnstableThisShouldNotBeListed; "#, expect![[r#" - fn main() fn() + fn main() fn() md std - bt u32 u32 + bt u32 u32 kw async kw const kw crate:: @@ -2057,9 +2057,9 @@ fn foo() { } "#, expect![[r#" - fn foo() fn() + fn foo() fn() md proc_macros - bt u32 u32 + bt u32 u32 kw async kw const kw crate:: diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs index 347febce01..15518e9837 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -1431,8 +1431,8 @@ fn foo() { "#, Some('_'), expect![[r#" - fn foo() fn() - bt u32 u32 + fn foo() fn() + bt u32 u32 kw async kw const kw crate::