@@ -28,6 +28,8 @@ use crate::{
28
28
//
29
29
// impl Version {
30
30
// /// Returns `true` if the version is [`Minor`].
31
+ // ///
32
+ // /// [`Minor`]: Version::Minor
31
33
// fn is_minor(&self) -> bool {
32
34
// matches!(self, Self::Minor)
33
35
// }
@@ -43,7 +45,8 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) ->
43
45
ast:: StructKind :: Unit => "" ,
44
46
} ;
45
47
46
- let enum_lowercase_name = to_lower_snake_case ( & parent_enum. name ( ) ?. to_string ( ) ) ;
48
+ let enum_name = parent_enum. name ( ) ?;
49
+ let enum_lowercase_name = to_lower_snake_case ( & enum_name. to_string ( ) ) . replace ( '_' , " " ) ;
47
50
let fn_name = format ! ( "is_{}" , & to_lower_snake_case( & variant_name. text( ) ) ) ;
48
51
49
52
// Return early if we've found an existing new fn
@@ -57,11 +60,18 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) ->
57
60
|builder| {
58
61
let vis = parent_enum. visibility ( ) . map_or ( String :: new ( ) , |v| format ! ( "{} " , v) ) ;
59
62
let method = format ! (
60
- " /// Returns `true` if the {} is [`{}`].
63
+ " /// Returns `true` if the {} is [`{variant}`].
64
+ ///
65
+ /// [`{variant}`]: {}::{variant}
61
66
{}fn {}(&self) -> bool {{
62
- matches!(self, Self::{}{})
67
+ matches!(self, Self::{variant }{})
63
68
}}" ,
64
- enum_lowercase_name, variant_name, vis, fn_name, variant_name, pattern_suffix,
69
+ enum_lowercase_name,
70
+ enum_name,
71
+ vis,
72
+ fn_name,
73
+ pattern_suffix,
74
+ variant = variant_name
65
75
) ;
66
76
67
77
add_method_to_adt ( builder, & parent_enum, impl_def, & method) ;
@@ -93,6 +103,8 @@ enum Variant {
93
103
94
104
impl Variant {
95
105
/// Returns `true` if the variant is [`Minor`].
106
+ ///
107
+ /// [`Minor`]: Variant::Minor
96
108
fn is_minor(&self) -> bool {
97
109
matches!(self, Self::Minor)
98
110
}
@@ -137,6 +149,8 @@ enum Variant {
137
149
138
150
impl Variant {
139
151
/// Returns `true` if the variant is [`Minor`].
152
+ ///
153
+ /// [`Minor`]: Variant::Minor
140
154
fn is_minor(&self) -> bool {
141
155
matches!(self, Self::Minor(..))
142
156
}
@@ -162,6 +176,8 @@ enum Variant {
162
176
163
177
impl Variant {
164
178
/// Returns `true` if the variant is [`Minor`].
179
+ ///
180
+ /// [`Minor`]: Variant::Minor
165
181
fn is_minor(&self) -> bool {
166
182
matches!(self, Self::Minor { .. })
167
183
}
@@ -179,6 +195,8 @@ enum Variant { Undefined }
179
195
180
196
impl Variant {
181
197
/// Returns `true` if the variant is [`Undefined`].
198
+ ///
199
+ /// [`Undefined`]: Variant::Undefined
182
200
fn is_undefined(&self) -> bool {
183
201
matches!(self, Self::Undefined)
184
202
}
@@ -204,6 +222,8 @@ pub(crate) enum Variant {
204
222
205
223
impl Variant {
206
224
/// Returns `true` if the variant is [`Minor`].
225
+ ///
226
+ /// [`Minor`]: Variant::Minor
207
227
pub(crate) fn is_minor(&self) -> bool {
208
228
matches!(self, Self::Minor)
209
229
}
@@ -224,6 +244,8 @@ enum Variant {
224
244
225
245
impl Variant {
226
246
/// Returns `true` if the variant is [`Minor`].
247
+ ///
248
+ /// [`Minor`]: Variant::Minor
227
249
fn is_minor(&self) -> bool {
228
250
matches!(self, Self::Minor)
229
251
}
@@ -236,14 +258,45 @@ impl Variant {
236
258
237
259
impl Variant {
238
260
/// Returns `true` if the variant is [`Minor`].
261
+ ///
262
+ /// [`Minor`]: Variant::Minor
239
263
fn is_minor(&self) -> bool {
240
264
matches!(self, Self::Minor)
241
265
}
242
266
243
267
/// Returns `true` if the variant is [`Major`].
268
+ ///
269
+ /// [`Major`]: Variant::Major
244
270
fn is_major(&self) -> bool {
245
271
matches!(self, Self::Major)
246
272
}
273
+ }"# ,
274
+ ) ;
275
+ }
276
+
277
+ #[ test]
278
+ fn test_generate_enum_is_variant_names ( ) {
279
+ check_assist (
280
+ generate_enum_is_method,
281
+ r#"
282
+ enum GeneratorState {
283
+ Yielded,
284
+ Complete$0,
285
+ Major,
286
+ }"# ,
287
+ r#"enum GeneratorState {
288
+ Yielded,
289
+ Complete,
290
+ Major,
291
+ }
292
+
293
+ impl GeneratorState {
294
+ /// Returns `true` if the generator state is [`Complete`].
295
+ ///
296
+ /// [`Complete`]: GeneratorState::Complete
297
+ fn is_complete(&self) -> bool {
298
+ matches!(self, Self::Complete)
299
+ }
247
300
}"# ,
248
301
) ;
249
302
}
0 commit comments