From 2a182f3f1f2c7b1a5359885b3b55e20885fe4183 Mon Sep 17 00:00:00 2001 From: hecatia-elegua <108802164+hecatia-elegua@users.noreply.github.com> Date: Wed, 10 May 2023 12:51:08 +0200 Subject: [PATCH] Add doc(alias)-based method completion --- crates/ide-completion/src/completions.rs | 12 ++++- crates/ide-completion/src/tests/special.rs | 56 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs index bc7a94cd337..87346f501d2 100644 --- a/crates/ide-completion/src/completions.rs +++ b/crates/ide-completion/src/completions.rs @@ -295,9 +295,12 @@ impl Completions { Visible::Editable => true, Visible::No => return, }; + let doc_aliases = ctx.doc_aliases(&func); self.add( render_fn( - RenderContext::new(ctx).private_editable(is_private_editable), + RenderContext::new(ctx) + .private_editable(is_private_editable) + .doc_aliases(doc_aliases), path_ctx, local_name, func, @@ -322,9 +325,12 @@ impl Completions { Visible::Editable => true, Visible::No => return, }; + let doc_aliases = ctx.doc_aliases(&func); self.add( render_method( - RenderContext::new(ctx).private_editable(is_private_editable), + RenderContext::new(ctx) + .private_editable(is_private_editable) + .doc_aliases(doc_aliases), dot_access, receiver, local_name, @@ -349,10 +355,12 @@ impl Completions { Visible::Editable => true, Visible::No => return, }; + let doc_aliases = ctx.doc_aliases(&func); self.add( render_method( RenderContext::new(ctx) .private_editable(is_private_editable) + .doc_aliases(doc_aliases) .import_to_add(Some(import)), dot_access, None, diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs index e23f3ae72eb..3824720839e 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -1106,6 +1106,62 @@ fn here_we_go() { ); } +#[test] +fn completes_struct_fn_name_via_doc_alias_in_fn_body() { + check( + r#" +struct Foo; +impl Foo { + #[doc(alias = "qux")] + fn bar() -> u8 { 1 } +} + +fn here_we_go() { + Foo::q$0 +} +"#, + expect![[r#" + fn bar() (alias qux) fn() -> u8 + "#]], + ); +} + +#[test] +fn completes_method_name_via_doc_alias_in_fn_body() { + check( + r#" +struct Foo { + bar: u8 +} +impl Foo { + #[doc(alias = "qux")] + fn baz(&self) -> u8 { + self.bar + } +} + +fn here_we_go() { + let foo = Foo { field: 42 }; + foo.q$0 +} +"#, + expect![[r#" + fd bar u8 + me baz() (alias qux) fn(&self) -> u8 + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn let let + sn letm let mut + sn match match expr {} + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + "#]], + ); +} + #[test] fn completes_fn_name_via_doc_alias_in_fn_body() { check(