diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs index 818ec3de337..e5c18f362b7 100644 --- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs @@ -125,7 +125,6 @@ fn add_missing_impl_members_inner( if let IgnoreAssocItems::HiddenDocAttrPresent = ignore_items { // Relax condition for local crates. - let db = ctx.db(); if trait_.module(db).krate().origin(db).is_local() { ign_item = IgnoreAssocItems::No; @@ -1987,6 +1986,7 @@ impl AnotherTrait for () { #[test] fn doc_hidden_default_impls_ignored() { + // doc(hidden) attr is ignored trait and impl both belong to the local crate. check_assist( add_missing_default_members, r#" @@ -2025,7 +2025,7 @@ fn another_default_impl() -> u32 { } #[test] - fn doc_hidden_default_impls_extern_crates() { + fn doc_hidden_default_impls_lang_crates() { // Not applicable because Eq has a single method and this has a #[doc(hidden)] attr set. check_assist_not_applicable( add_missing_default_members, @@ -2037,4 +2037,115 @@ impl E$0q for Foo { /* $0 */ } "#, ) } + + #[test] + fn doc_hidden_default_impls_lib_crates() { + check_assist( + add_missing_default_members, + r#" + //- /main.rs crate:a deps:b + struct B; + impl b::Exte$0rnTrait for B {} + //- /lib.rs crate:b new_source_root:library + pub trait ExternTrait { + #[doc(hidden)] + fn hidden_default() -> Option<()> { + todo!() + } + + fn unhidden_default() -> Option<()> { + todo!() + } + + fn unhidden_nondefault() -> Option<()>; + } + "#, + r#" + struct B; + impl b::ExternTrait for B { + $0fn unhidden_default() -> Option<()> { + todo!() + } + } + "#, + ) + } + + #[test] + fn doc_hidden_default_impls_local_crates() { + check_assist( + add_missing_default_members, + r#" +trait LocalTrait { + #[doc(hidden)] + fn no_skip_default() -> Option<()> { + todo!() + } + fn no_skip_default_2() -> Option<()> { + todo!() + } +} + +struct B; +impl Loc$0alTrait for B {} + "#, + r#" +trait LocalTrait { + #[doc(hidden)] + fn no_skip_default() -> Option<()> { + todo!() + } + fn no_skip_default_2() -> Option<()> { + todo!() + } +} + +struct B; +impl LocalTrait for B { + $0fn no_skip_default() -> Option<()> { + todo!() + } + + fn no_skip_default_2() -> Option<()> { + todo!() + } +} + "#, + ) + } + + #[test] + fn doc_hidden_default_impls_workspace_crates() { + check_assist( + add_missing_default_members, + r#" +//- /lib.rs crate:b new_source_root:local +trait LocalTrait { + #[doc(hidden)] + fn no_skip_default() -> Option<()> { + todo!() + } + fn no_skip_default_2() -> Option<()> { + todo!() + } +} + +//- /main.rs crate:a deps:b +struct B; +impl b::Loc$0alTrait for B {} + "#, + r#" +struct B; +impl b::LocalTrait for B { + $0fn no_skip_default() -> Option<()> { + todo!() + } + + fn no_skip_default_2() -> Option<()> { + todo!() + } +} + "#, + ) + } } diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs index e09af5ce302..aab4f15f141 100644 --- a/crates/ide-assists/src/utils.rs +++ b/crates/ide-assists/src/utils.rs @@ -109,6 +109,7 @@ pub fn filter_assoc_items( !(ignore_items == IgnoreAssocItems::HiddenDocAttrPresent && assoc_item.attrs(sema.db).has_doc_hidden()) }) + // Note: This throws away items with no source. .filter_map(|assoc_item| { let item = match assoc_item { hir::AssocItem::Function(it) => sema.source(it)?.map(ast::AssocItem::Fn), @@ -118,7 +119,6 @@ pub fn filter_assoc_items( Some(item) }) .filter(has_def_name) - // Note: This throws away items with no source. .filter(|it| match &it.value { ast::AssocItem::Fn(def) => matches!( (default_methods, def.body()),