Skip to content

Commit 7ad378f

Browse files
committed
Complete modules in assoc item lists
1 parent 3a16950 commit 7ad378f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
2727
if let ScopeDef::MacroDef(macro_def) = def {
2828
acc.add_macro(ctx, Some(name.to_string()), macro_def);
2929
}
30+
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
31+
acc.add_resolution(ctx, name.to_string(), &def);
32+
}
3033
}
3134
}
3235
return;
@@ -614,19 +617,20 @@ fn main() { let _ = crate::$0 }
614617
}
615618

616619
#[test]
617-
fn completes_qualified_macros_in_impl() {
620+
fn completes_in_assoc_item_list() {
618621
check(
619622
r#"
620623
#[macro_export]
621624
macro_rules! foo { () => {} }
625+
mod bar {}
622626
623627
struct MyStruct {}
624-
625628
impl MyStruct {
626629
crate::$0
627630
}
628631
"#,
629632
expect![[r##"
633+
md bar
630634
ma foo! #[macro_export] macro_rules! foo
631635
"##]],
632636
);

crates/ide_completion/src/completions/unqualified_path.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
1717
if let ScopeDef::MacroDef(macro_def) = def {
1818
acc.add_macro(ctx, Some(name.to_string()), macro_def);
1919
}
20+
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
21+
acc.add_resolution(ctx, name.to_string(), &def);
22+
}
2023
});
2124
return;
2225
}
@@ -672,17 +675,19 @@ impl My$0
672675
}
673676

674677
#[test]
675-
fn only_completes_macros_in_assoc_item_list() {
678+
fn completes_in_assoc_item_list() {
676679
check(
677680
r#"
678-
struct MyStruct {}
679681
macro_rules! foo {}
682+
mod bar {}
680683
684+
struct MyStruct {}
681685
impl MyStruct {
682686
$0
683687
}
684688
"#,
685689
expect![[r#"
690+
md bar
686691
ma foo! macro_rules! foo
687692
"#]],
688693
)

crates/ide_completion/src/patterns.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub(crate) fn determine_location(tok: SyntaxToken) -> Option<ImmediateLocation>
6262
ast::SourceFile(_it) => ImmediateLocation::ItemList,
6363
ast::ItemList(_it) => ImmediateLocation::ItemList,
6464
ast::RefExpr(_it) => ImmediateLocation::RefExpr,
65-
ast::RefPat(_it) => ImmediateLocation::RefExpr,
6665
ast::RecordField(_it) => ImmediateLocation::RecordField,
6766
ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) {
6867
Some(IMPL) => ImmediateLocation::Impl,

0 commit comments

Comments
 (0)