aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers/generate_enum_match_method.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/handlers/generate_enum_match_method.rs')
-rw-r--r--crates/assists/src/handlers/generate_enum_match_method.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs
index ee89d4208..4cf66b5d5 100644
--- a/crates/assists/src/handlers/generate_enum_match_method.rs
+++ b/crates/assists/src/handlers/generate_enum_match_method.rs
@@ -1,9 +1,12 @@
1use stdx::{format_to, to_lower_snake_case}; 1use stdx::{format_to, to_lower_snake_case};
2use syntax::ast::VisibilityOwner;
2use syntax::ast::{self, AstNode, NameOwner}; 3use syntax::ast::{self, AstNode, NameOwner};
3use syntax::{ast::VisibilityOwner, T};
4use test_utils::mark; 4use test_utils::mark;
5 5
6use crate::{utils::find_struct_impl, AssistContext, AssistId, AssistKind, Assists}; 6use crate::{
7 utils::{find_impl_block, find_struct_impl},
8 AssistContext, AssistId, AssistKind, Assists,
9};
7 10
8// Assist: generate_enum_match_method 11// Assist: generate_enum_match_method
9// 12//
@@ -63,7 +66,6 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
63 } 66 }
64 67
65 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));
66
67 format_to!( 69 format_to!(
68 buf, 70 buf,
69 " /// Returns `true` if the {} is [`{}`]. 71 " /// Returns `true` if the {} is [`{}`].
@@ -78,17 +80,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
78 ); 80 );
79 81
80 let start_offset = impl_def 82 let start_offset = impl_def
81 .and_then(|impl_def| { 83 .and_then(|impl_def| find_impl_block(impl_def, &mut buf))
82 buf.push('\n');
83 let start = impl_def
84 .syntax()
85 .descendants_with_tokens()
86 .find(|t| t.kind() == T!['{'])?
87 .text_range()
88 .end();
89
90 Some(start)
91 })
92 .unwrap_or_else(|| { 84 .unwrap_or_else(|| {
93 buf = generate_impl_text(&parent_enum, &buf); 85 buf = generate_impl_text(&parent_enum, &buf);
94 parent_enum.syntax().text_range().end() 86 parent_enum.syntax().text_range().end()