Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b4515d9

Browse files
Add doc(alias)-based use and other mod completion
1 parent f87f468 commit b4515d9

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

crates/ide-completion/src/completions/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(crate) fn complete_expr_path(
8888
let module_scope = module.scope(ctx.db, Some(ctx.module));
8989
for (name, def) in module_scope {
9090
if scope_def_applicable(def) {
91-
acc.add_path_resolution(ctx, path_ctx, name, def, vec![]);
91+
acc.add_path_resolution(ctx, path_ctx, name, def, ctx.doc_aliases_in_scope(def));
9292
}
9393
}
9494
}

crates/ide-completion/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<'a> CompletionContext<'a> {
555555
self.krate != defining_crate && attrs.has_doc_hidden()
556556
}
557557

558-
fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec<SmolStr> {
558+
pub(crate) fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec<SmolStr> {
559559
if let Some(attrs) = scope_def.attrs(self.db) {
560560
attrs.doc_aliases().collect()
561561
} else {

crates/ide-completion/src/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ impl Builder {
409409
local_name: hir::Name,
410410
resolution: hir::ScopeDef,
411411
) -> Self {
412-
render_path_resolution(RenderContext::new(ctx), path_ctx, local_name, resolution)
412+
let doc_aliases = ctx.doc_aliases_in_scope(resolution);
413+
render_path_resolution(RenderContext::new(ctx).doc_aliases(doc_aliases), path_ctx, local_name, resolution)
413414
}
414415

415416
pub(crate) fn build(self) -> CompletionItem {

crates/ide-completion/src/tests/special.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,3 +1150,42 @@ fn bar() { qu$0 }
11501150
"#]],
11511151
);
11521152
}
1153+
1154+
#[test]
1155+
fn completes_struct_name_via_doc_alias_in_another_mod() {
1156+
check(
1157+
r#"
1158+
mod foo {
1159+
#[doc(alias = "Qux")]
1160+
pub struct Bar(u8);
1161+
}
1162+
1163+
fn here_we_go() {
1164+
use foo;
1165+
let foo = foo::Q$0
1166+
}
1167+
"#,
1168+
expect![[r#"
1169+
st Bar (alias Qux)
1170+
"#]],
1171+
);
1172+
}
1173+
1174+
#[test]
1175+
fn completes_use_via_doc_alias_in_another_mod() {
1176+
check(
1177+
r#"
1178+
mod foo {
1179+
#[doc(alias = "Qux")]
1180+
pub struct Bar(u8);
1181+
}
1182+
1183+
fn here_we_go() {
1184+
use foo::Q$0;
1185+
}
1186+
"#,
1187+
expect![[r#"
1188+
st Bar (alias Qux)
1189+
"#]],
1190+
);
1191+
}

0 commit comments

Comments
 (0)