From 46b4f89c920c314caf1a8af2abdb09732d100d67 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Jan 2021 01:56:11 +0300 Subject: . --- .../src/handlers/replace_derive_with_manual_impl.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'crates/assists/src/handlers/replace_derive_with_manual_impl.rs') 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; use itertools::Itertools; use syntax::{ ast::{self, make, AstNode}, - Direction, SmolStr, + Direction, SyntaxKind::{IDENT, WHITESPACE}, TextSize, }; @@ -43,17 +43,18 @@ pub(crate) fn replace_derive_with_manual_impl( ) -> Option<()> { let attr = ctx.find_node_at_offset::()?; - let attr_name = attr + let has_derive = attr .syntax() .descendants_with_tokens() .filter(|t| t.kind() == IDENT) .find_map(syntax::NodeOrToken::into_token) - .filter(|t| t.text() == "derive")? - .text() - .clone(); + .filter(|t| t.text() == "derive") + .is_some(); + if !has_derive { + return None; + } - let trait_token = - ctx.token_at_offset().find(|t| t.kind() == IDENT && *t.text() != attr_name)?; + let trait_token = ctx.token_at_offset().find(|t| t.kind() == IDENT && t.text() != "derive")?; let trait_path = make::path_unqualified(make::path_segment(make::name_ref(trait_token.text()))); let annotated_name = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; @@ -176,9 +177,9 @@ fn update_attribute( .syntax() .descendants_with_tokens() .filter(|t| t.kind() == IDENT) - .filter_map(|t| t.into_token().map(|t| t.text().clone())) + .filter_map(|t| t.into_token().map(|t| t.text().to_string())) .filter(|t| t != trait_name.text()) - .collect::>(); + .collect::>(); let has_more_derives = !new_attr_input.is_empty(); if has_more_derives { -- cgit v1.2.3