mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Only complete ancestors and self in visibility path completions
This commit is contained in:
parent
3956a5b757
commit
ccde0bcd1f
2 changed files with 44 additions and 13 deletions
|
@ -28,22 +28,40 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
|
|
||||||
let context_module = ctx.scope.module();
|
let context_module = ctx.scope.module();
|
||||||
|
|
||||||
if let Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) =
|
match ctx.completion_location {
|
||||||
ctx.completion_location
|
Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) => {
|
||||||
{
|
if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
|
||||||
if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
|
for (name, def) in module.scope(ctx.db, context_module) {
|
||||||
for (name, def) in module.scope(ctx.db, context_module) {
|
if let hir::ScopeDef::MacroDef(macro_def) = def {
|
||||||
if let hir::ScopeDef::MacroDef(macro_def) = def {
|
if macro_def.is_fn_like() {
|
||||||
if macro_def.is_fn_like() {
|
acc.add_macro(ctx, Some(name.clone()), macro_def);
|
||||||
acc.add_macro(ctx, Some(name.clone()), macro_def);
|
}
|
||||||
|
}
|
||||||
|
if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
|
||||||
|
acc.add_resolution(ctx, name, &def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
|
}
|
||||||
acc.add_resolution(ctx, name, &def);
|
return;
|
||||||
|
}
|
||||||
|
Some(ImmediateLocation::Visibility(_)) => {
|
||||||
|
if let hir::PathResolution::Def(hir::ModuleDef::Module(resolved)) = resolution {
|
||||||
|
if let Some(current_module) = ctx.scope.module() {
|
||||||
|
if let Some(next) = current_module
|
||||||
|
.path_to_root(ctx.db)
|
||||||
|
.into_iter()
|
||||||
|
.take_while(|&it| it != resolved)
|
||||||
|
.next()
|
||||||
|
{
|
||||||
|
if let Some(name) = next.name(ctx.db) {
|
||||||
|
acc.add_resolution(ctx, name, &hir::ScopeDef::ModuleDef(next.into()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.in_use_tree() {
|
if ctx.in_use_tree() {
|
||||||
|
|
|
@ -40,7 +40,6 @@ pub(in $0)
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn qualified() {
|
fn qualified() {
|
||||||
// FIXME: only show parent modules
|
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
mod foo {
|
mod foo {
|
||||||
|
@ -50,7 +49,21 @@ mod foo {
|
||||||
mod bar {}
|
mod bar {}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
md bar
|
md foo
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod qux {
|
||||||
|
mod foo {
|
||||||
|
pub(in crate::qux::$0)
|
||||||
|
}
|
||||||
|
mod baz {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod bar {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
md foo
|
md foo
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue