aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/assist_context.rs4
-rw-r--r--crates/assists/src/handlers/generate_enum_match_method.rs10
-rw-r--r--crates/assists/src/tests/generated.rs1
3 files changed, 12 insertions, 3 deletions
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs
index 8d93edba2..bba6c08e0 100644
--- a/crates/assists/src/assist_context.rs
+++ b/crates/assists/src/assist_context.rs
@@ -162,7 +162,7 @@ impl Assists {
162 } else { 162 } else {
163 None 163 None
164 }; 164 };
165 assist.source_change = source_change.clone(); 165 assist.source_change = source_change;
166 166
167 self.buf.push(assist); 167 self.buf.push(assist);
168 Some(()) 168 Some(())
@@ -242,7 +242,7 @@ impl AssistBuilder {
242 } 242 }
243 pub(crate) fn create_file(&mut self, dst: AnchoredPathBuf, content: impl Into<String>) { 243 pub(crate) fn create_file(&mut self, dst: AnchoredPathBuf, content: impl Into<String>) {
244 let file_system_edit = 244 let file_system_edit =
245 FileSystemEdit::CreateFile { dst: dst.clone(), initial_contents: content.into() }; 245 FileSystemEdit::CreateFile { dst: dst, initial_contents: content.into() };
246 self.source_change.push_file_system_edit(file_system_edit); 246 self.source_change.push_file_system_edit(file_system_edit);
247 } 247 }
248 248
diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs
index 2345a61c1..4cf66b5d5 100644
--- a/crates/assists/src/handlers/generate_enum_match_method.rs
+++ b/crates/assists/src/handlers/generate_enum_match_method.rs
@@ -28,6 +28,7 @@ use crate::{
28// } 28// }
29// 29//
30// impl Version { 30// impl Version {
31// /// Returns `true` if the version is [`Minor`].
31// fn is_minor(&self) -> bool { 32// fn is_minor(&self) -> bool {
32// matches!(self, Self::Minor) 33// matches!(self, Self::Minor)
33// } 34// }
@@ -42,6 +43,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
42 return None; 43 return None;
43 } 44 }
44 45
46 let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string());
45 let fn_name = to_lower_snake_case(&variant_name.to_string()); 47 let fn_name = to_lower_snake_case(&variant_name.to_string());
46 48
47 // Return early if we've found an existing new fn 49 // Return early if we've found an existing new fn
@@ -66,9 +68,12 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
66 let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v)); 68 let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v));
67 format_to!( 69 format_to!(
68 buf, 70 buf,
69 " {}fn is_{}(&self) -> bool {{ 71 " /// Returns `true` if the {} is [`{}`].
72 {}fn is_{}(&self) -> bool {{
70 matches!(self, Self::{}) 73 matches!(self, Self::{})
71 }}", 74 }}",
75 enum_lowercase_name,
76 variant_name,
72 vis, 77 vis,
73 fn_name, 78 fn_name,
74 variant_name 79 variant_name
@@ -125,6 +130,7 @@ enum Variant {
125} 130}
126 131
127impl Variant { 132impl Variant {
133 /// Returns `true` if the variant is [`Minor`].
128 fn is_minor(&self) -> bool { 134 fn is_minor(&self) -> bool {
129 matches!(self, Self::Minor) 135 matches!(self, Self::Minor)
130 } 136 }
@@ -172,6 +178,7 @@ enum Variant {
172enum Variant { Undefined } 178enum Variant { Undefined }
173 179
174impl Variant { 180impl Variant {
181 /// Returns `true` if the variant is [`Undefined`].
175 fn is_undefined(&self) -> bool { 182 fn is_undefined(&self) -> bool {
176 matches!(self, Self::Undefined) 183 matches!(self, Self::Undefined)
177 } 184 }
@@ -196,6 +203,7 @@ pub(crate) enum Variant {
196} 203}
197 204
198impl Variant { 205impl Variant {
206 /// Returns `true` if the variant is [`Minor`].
199 pub(crate) fn is_minor(&self) -> bool { 207 pub(crate) fn is_minor(&self) -> bool {
200 matches!(self, Self::Minor) 208 matches!(self, Self::Minor)
201 } 209 }
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs
index 960815bd9..0dbb05f2a 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -478,6 +478,7 @@ enum Version {
478} 478}
479 479
480impl Version { 480impl Version {
481 /// Returns `true` if the version is [`Minor`].
481 fn is_minor(&self) -> bool { 482 fn is_minor(&self) -> bool {
482 matches!(self, Self::Minor) 483 matches!(self, Self::Minor)
483 } 484 }