mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 17:58:16 +00:00
Merge #9665
9665: Only complete ancestors and self in visibility path completions r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
4d457e26e1
2 changed files with 44 additions and 13 deletions
|
@ -28,9 +28,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
|||
|
||||
let context_module = ctx.scope.module();
|
||||
|
||||
if let Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) =
|
||||
ctx.completion_location
|
||||
{
|
||||
match ctx.completion_location {
|
||||
Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) => {
|
||||
if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
|
||||
for (name, def) in module.scope(ctx.db, context_module) {
|
||||
if let hir::ScopeDef::MacroDef(macro_def) = def {
|
||||
|
@ -45,6 +44,25 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
|||
}
|
||||
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;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if ctx.in_use_tree() {
|
||||
if iter::successors(Some(path.clone()), |p| p.qualifier())
|
||||
|
|
|
@ -40,7 +40,6 @@ pub(in $0)
|
|||
|
||||
#[test]
|
||||
fn qualified() {
|
||||
// FIXME: only show parent modules
|
||||
check(
|
||||
r#"
|
||||
mod foo {
|
||||
|
@ -50,7 +49,21 @@ mod foo {
|
|||
mod bar {}
|
||||
"#,
|
||||
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
|
||||
"#]],
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue