diff options
author | Aleksey Kladov <[email protected]> | 2021-01-19 22:56:11 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-01-19 22:56:11 +0000 |
commit | 46b4f89c920c314caf1a8af2abdb09732d100d67 (patch) | |
tree | 1f01586d15be6fbcbcb6a40194ab6f1f723a36b7 /crates/assists/src/handlers/replace_derive_with_manual_impl.rs | |
parent | 63f509f4924e7448b9131514bbdd7a4da5292cd1 (diff) |
.
Diffstat (limited to 'crates/assists/src/handlers/replace_derive_with_manual_impl.rs')
-rw-r--r-- | crates/assists/src/handlers/replace_derive_with_manual_impl.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs index bd4c1c806..6aa9d2f2c 100644 --- a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs | |||
@@ -3,7 +3,7 @@ use ide_db::imports_locator; | |||
3 | use itertools::Itertools; | 3 | use itertools::Itertools; |
4 | use syntax::{ | 4 | use syntax::{ |
5 | ast::{self, make, AstNode}, | 5 | ast::{self, make, AstNode}, |
6 | Direction, SmolStr, | 6 | Direction, |
7 | SyntaxKind::{IDENT, WHITESPACE}, | 7 | SyntaxKind::{IDENT, WHITESPACE}, |
8 | TextSize, | 8 | TextSize, |
9 | }; | 9 | }; |
@@ -43,17 +43,18 @@ pub(crate) fn replace_derive_with_manual_impl( | |||
43 | ) -> Option<()> { | 43 | ) -> Option<()> { |
44 | let attr = ctx.find_node_at_offset::<ast::Attr>()?; | 44 | let attr = ctx.find_node_at_offset::<ast::Attr>()?; |
45 | 45 | ||
46 | let attr_name = attr | 46 | let has_derive = attr |
47 | .syntax() | 47 | .syntax() |
48 | .descendants_with_tokens() | 48 | .descendants_with_tokens() |
49 | .filter(|t| t.kind() == IDENT) | 49 | .filter(|t| t.kind() == IDENT) |
50 | .find_map(syntax::NodeOrToken::into_token) | 50 | .find_map(syntax::NodeOrToken::into_token) |
51 | .filter(|t| t.text() == "derive")? | 51 | .filter(|t| t.text() == "derive") |
52 | .text() | 52 | .is_some(); |
53 | .clone(); | 53 | if !has_derive { |
54 | return None; | ||
55 | } | ||
54 | 56 | ||
55 | let trait_token = | 57 | let trait_token = ctx.token_at_offset().find(|t| t.kind() == IDENT && t.text() != "derive")?; |
56 | ctx.token_at_offset().find(|t| t.kind() == IDENT && *t.text() != attr_name)?; | ||
57 | let trait_path = make::path_unqualified(make::path_segment(make::name_ref(trait_token.text()))); | 58 | let trait_path = make::path_unqualified(make::path_segment(make::name_ref(trait_token.text()))); |
58 | 59 | ||
59 | let annotated_name = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; | 60 | let annotated_name = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; |
@@ -176,9 +177,9 @@ fn update_attribute( | |||
176 | .syntax() | 177 | .syntax() |
177 | .descendants_with_tokens() | 178 | .descendants_with_tokens() |
178 | .filter(|t| t.kind() == IDENT) | 179 | .filter(|t| t.kind() == IDENT) |
179 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) | 180 | .filter_map(|t| t.into_token().map(|t| t.text().to_string())) |
180 | .filter(|t| t != trait_name.text()) | 181 | .filter(|t| t != trait_name.text()) |
181 | .collect::<Vec<SmolStr>>(); | 182 | .collect::<Vec<_>>(); |
182 | let has_more_derives = !new_attr_input.is_empty(); | 183 | let has_more_derives = !new_attr_input.is_empty(); |
183 | 184 | ||
184 | if has_more_derives { | 185 | if has_more_derives { |