aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/generate_from_impl_for_enum.rs2
-rw-r--r--crates/assists/src/handlers/generate_impl.rs2
-rw-r--r--crates/assists/src/handlers/replace_derive_with_manual_impl.rs24
-rw-r--r--crates/assists/src/utils.rs7
4 files changed, 21 insertions, 14 deletions
diff --git a/crates/assists/src/handlers/generate_from_impl_for_enum.rs b/crates/assists/src/handlers/generate_from_impl_for_enum.rs
index fac2447c9..d9388a737 100644
--- a/crates/assists/src/handlers/generate_from_impl_for_enum.rs
+++ b/crates/assists/src/handlers/generate_from_impl_for_enum.rs
@@ -3,7 +3,7 @@ use ide_db::RootDatabase;
3use syntax::ast::{self, AstNode, NameOwner}; 3use syntax::ast::{self, AstNode, NameOwner};
4use test_utils::mark; 4use test_utils::mark;
5 5
6use crate::{AssistContext, AssistId, AssistKind, Assists, utils::generate_trait_impl_text}; 6use crate::{utils::generate_trait_impl_text, AssistContext, AssistId, AssistKind, Assists};
7 7
8// Assist: generate_from_impl_for_enum 8// Assist: generate_from_impl_for_enum
9// 9//
diff --git a/crates/assists/src/handlers/generate_impl.rs b/crates/assists/src/handlers/generate_impl.rs
index e2762e5d2..050bcd4e2 100644
--- a/crates/assists/src/handlers/generate_impl.rs
+++ b/crates/assists/src/handlers/generate_impl.rs
@@ -1,6 +1,6 @@
1use syntax::ast::{self, AstNode, NameOwner}; 1use syntax::ast::{self, AstNode, NameOwner};
2 2
3use crate::{AssistContext, AssistId, AssistKind, Assists, utils::generate_impl_text}; 3use crate::{utils::generate_impl_text, AssistContext, AssistId, AssistKind, Assists};
4 4
5// Assist: generate_impl 5// Assist: generate_impl
6// 6//
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 7f44d752f..c69bc5cac 100644
--- a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -1,9 +1,20 @@
1use ide_db::helpers::mod_path_to_ast; 1use ide_db::helpers::mod_path_to_ast;
2use ide_db::imports_locator; 2use ide_db::imports_locator;
3use itertools::Itertools; 3use itertools::Itertools;
4use syntax::{SyntaxKind::{IDENT, WHITESPACE}, TextSize, ast::{self, AstNode, NameOwner, make}}; 4use syntax::{
5 5 ast::{self, make, AstNode, NameOwner},
6use crate::{AssistId, AssistKind, assist_context::{AssistBuilder, AssistContext, Assists}, utils::{Cursor, DefaultMethods, add_trait_assoc_items_to_impl, filter_assoc_items, generate_trait_impl_text, render_snippet}}; 6 SyntaxKind::{IDENT, WHITESPACE},
7 TextSize,
8};
9
10use crate::{
11 assist_context::{AssistBuilder, AssistContext, Assists},
12 utils::{
13 add_trait_assoc_items_to_impl, filter_assoc_items, generate_trait_impl_text,
14 render_snippet, Cursor, DefaultMethods,
15 },
16 AssistId, AssistKind,
17};
7 18
8// Assist: replace_derive_with_manual_impl 19// Assist: replace_derive_with_manual_impl
9// 20//
@@ -105,10 +116,9 @@ fn add_assist(
105 update_attribute(builder, &input, &trait_name, &attr); 116 update_attribute(builder, &input, &trait_name, &attr);
106 let trait_path = format!("{}", trait_path); 117 let trait_path = format!("{}", trait_path);
107 match (ctx.config.snippet_cap, impl_def_with_items) { 118 match (ctx.config.snippet_cap, impl_def_with_items) {
108 (None, _) => builder.insert( 119 (None, _) => {
109 insert_pos, 120 builder.insert(insert_pos, generate_trait_impl_text(adt, &trait_path, ""))
110 generate_trait_impl_text(adt, &trait_path, ""), 121 }
111 ),
112 (Some(cap), None) => builder.insert_snippet( 122 (Some(cap), None) => builder.insert_snippet(
113 cap, 123 cap,
114 insert_pos, 124 insert_pos,
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs
index b51d703db..98c4462bb 100644
--- a/crates/assists/src/utils.rs
+++ b/crates/assists/src/utils.rs
@@ -380,11 +380,8 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
380 let type_params = adt.generic_param_list(); 380 let type_params = adt.generic_param_list();
381 let mut buf = String::with_capacity(code.len()); 381 let mut buf = String::with_capacity(code.len());
382 buf.push_str("\n\n"); 382 buf.push_str("\n\n");
383 adt 383 adt.attrs()
384 .attrs() 384 .filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false))
385 .filter(|attr| {
386 attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false)
387 })
388 .for_each(|attr| buf.push_str(format!("{}\n", attr.to_string()).as_str())); 385 .for_each(|attr| buf.push_str(format!("{}\n", attr.to_string()).as_str()));
389 buf.push_str("impl"); 386 buf.push_str("impl");
390 if let Some(type_params) = &type_params { 387 if let Some(type_params) = &type_params {