mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-17 02:08:30 +00:00
Add doc(alias)-based use and other mod completion
This commit is contained in:
parent
f87f468dbd
commit
b4515d987f
4 changed files with 43 additions and 3 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
"#]],
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue