From b4515d987f53c5d874b69609f15708f503d3b32e Mon Sep 17 00:00:00 2001 From: hecatia-elegua <108802164+hecatia-elegua@users.noreply.github.com> Date: Wed, 5 Apr 2023 22:08:59 +0200 Subject: [PATCH] Add doc(alias)-based use and other mod completion --- crates/ide-completion/src/completions/expr.rs | 2 +- crates/ide-completion/src/context.rs | 2 +- crates/ide-completion/src/item.rs | 3 +- crates/ide-completion/src/tests/special.rs | 39 +++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs index 70c91e6a10..19f4d65320 100644 --- a/crates/ide-completion/src/completions/expr.rs +++ b/crates/ide-completion/src/completions/expr.rs @@ -88,7 +88,7 @@ pub(crate) fn complete_expr_path( let module_scope = module.scope(ctx.db, Some(ctx.module)); for (name, def) in module_scope { if scope_def_applicable(def) { - acc.add_path_resolution(ctx, path_ctx, name, def, vec![]); + acc.add_path_resolution(ctx, path_ctx, name, def, ctx.doc_aliases_in_scope(def)); } } } diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs index f9bc13f7d2..6089f18ac6 100644 --- a/crates/ide-completion/src/context.rs +++ b/crates/ide-completion/src/context.rs @@ -555,7 +555,7 @@ impl<'a> CompletionContext<'a> { self.krate != defining_crate && attrs.has_doc_hidden() } - fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec { + pub(crate) fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec { if let Some(attrs) = scope_def.attrs(self.db) { attrs.doc_aliases().collect() } else { diff --git a/crates/ide-completion/src/item.rs b/crates/ide-completion/src/item.rs index ab27b8c0a9..a993ea8e90 100644 --- a/crates/ide-completion/src/item.rs +++ b/crates/ide-completion/src/item.rs @@ -409,7 +409,8 @@ impl Builder { local_name: hir::Name, resolution: hir::ScopeDef, ) -> Self { - render_path_resolution(RenderContext::new(ctx), path_ctx, local_name, resolution) + let doc_aliases = ctx.doc_aliases_in_scope(resolution); + render_path_resolution(RenderContext::new(ctx).doc_aliases(doc_aliases), path_ctx, local_name, resolution) } pub(crate) fn build(self) -> CompletionItem { diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs index 8d9bd4ba1a..e11a2c4797 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -1150,3 +1150,42 @@ fn bar() { qu$0 } "#]], ); } + +#[test] +fn completes_struct_name_via_doc_alias_in_another_mod() { + check( + r#" +mod foo { + #[doc(alias = "Qux")] + pub struct Bar(u8); +} + +fn here_we_go() { + use foo; + let foo = foo::Q$0 +} +"#, + expect![[r#" + st Bar (alias Qux) + "#]], + ); +} + +#[test] +fn completes_use_via_doc_alias_in_another_mod() { + check( + r#" +mod foo { + #[doc(alias = "Qux")] + pub struct Bar(u8); +} + +fn here_we_go() { + use foo::Q$0; +} +"#, + expect![[r#" + st Bar (alias Qux) + "#]], + ); +} \ No newline at end of file