Add doc(alias)-based use and other mod completion

This commit is contained in:
hecatia-elegua 2023-04-05 22:08:59 +02:00
parent f87f468dbd
commit b4515d987f
4 changed files with 43 additions and 3 deletions

View file

@ -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));
}
}
}

View file

@ -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<SmolStr> {
pub(crate) fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec<SmolStr> {
if let Some(attrs) = scope_def.attrs(self.db) {
attrs.doc_aliases().collect()
} else {

View file

@ -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 {

View file

@ -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)
"#]],
);
}