Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs')
-rw-r--r--crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs28
1 files changed, 9 insertions, 19 deletions
diff --git a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
index 36ac8c71d8..3bdd795bea 100644
--- a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -1,8 +1,5 @@
use hir::{InFile, ModuleDef};
-use ide_db::{
- helpers::mod_path_to_ast, imports::import_assets::NameToImport, items_locator,
- syntax_helpers::insert_whitespace_into_node::insert_ws_into,
-};
+use ide_db::{helpers::mod_path_to_ast, imports::import_assets::NameToImport, items_locator};
use itertools::Itertools;
use syntax::{
ast::{self, AstNode, HasName},
@@ -182,7 +179,11 @@ fn impl_def_from_trait(
let impl_def = {
use syntax::ast::Impl;
let text = generate_trait_impl_text(adt, trait_path.to_string().as_str(), "");
- let parse = syntax::SourceFile::parse(&text);
+ // FIXME: `generate_trait_impl_text` currently generates two newlines
+ // at the front, but these leading newlines should really instead be
+ // inserted at the same time the impl is inserted
+ assert_eq!(&text[..2], "\n\n", "`generate_trait_impl_text` output changed");
+ let parse = syntax::SourceFile::parse(&text[2..]);
let node = match parse.tree().syntax().descendants().find_map(Impl::cast) {
Some(it) => it,
None => {
@@ -193,24 +194,13 @@ fn impl_def_from_trait(
)
}
};
- let node = node.clone_subtree();
+ let node = node.clone_for_update();
assert_eq!(node.syntax().text_range().start(), 0.into());
node
};
- let trait_items = trait_items
- .into_iter()
- .map(|it| {
- if sema.hir_file_for(it.syntax()).is_macro() {
- if let Some(it) = ast::AssocItem::cast(insert_ws_into(it.syntax().clone())) {
- return it;
- }
- }
- it.clone_for_update()
- })
- .collect();
- let (impl_def, first_assoc_item) =
- add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope);
+ let first_assoc_item =
+ add_trait_assoc_items_to_impl(sema, &trait_items, trait_, &impl_def, target_scope);
// Generate a default `impl` function body for the derived trait.
if let ast::AssocItem::Fn(ref func) = first_assoc_item {