File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ pub(crate) fn generate_default_from_enum_variant(
39
39
cov_mark:: hit!( test_gen_default_on_non_unit_variant_not_implemented) ;
40
40
return None ;
41
41
}
42
+ if !variant. syntax ( ) . text_range ( ) . contains_range ( ctx. selection_trimmed ( ) ) {
43
+ return None ;
44
+ }
42
45
43
46
if existing_default_impl ( & ctx. sema , & variant) . is_some ( ) {
44
47
cov_mark:: hit!( test_gen_default_impl_already_exists) ;
@@ -114,6 +117,49 @@ impl Default for Variant {
114
117
) ;
115
118
}
116
119
120
+ #[ test]
121
+ fn test_generate_default_selected_variant ( ) {
122
+ check_assist (
123
+ generate_default_from_enum_variant,
124
+ r#"
125
+ //- minicore: default
126
+ enum Variant {
127
+ Undefined,
128
+ $0Minor$0,
129
+ Major,
130
+ }
131
+ "# ,
132
+ r#"
133
+ enum Variant {
134
+ Undefined,
135
+ Minor,
136
+ Major,
137
+ }
138
+
139
+ impl Default for Variant {
140
+ fn default() -> Self {
141
+ Self::Minor
142
+ }
143
+ }
144
+ "# ,
145
+ ) ;
146
+ }
147
+
148
+ #[ test]
149
+ fn test_generate_default_not_applicable_with_multiple_variant_selection ( ) {
150
+ check_assist_not_applicable (
151
+ generate_default_from_enum_variant,
152
+ r#"
153
+ //- minicore: default
154
+ enum Variant {
155
+ Undefined,
156
+ $0Minor,
157
+ M$0ajor,
158
+ }
159
+ "# ,
160
+ ) ;
161
+ }
162
+
117
163
#[ test]
118
164
fn test_generate_default_already_implemented ( ) {
119
165
cov_mark:: check!( test_gen_default_impl_already_exists) ;
You can’t perform that action at this time.
0 commit comments