Complete modules in assoc item lists

This commit is contained in:
Lukas Wirth 2021-05-27 20:53:38 +02:00
parent 3a16950fd9
commit 7ad378fec0
3 changed files with 13 additions and 5 deletions

View file

@ -27,6 +27,9 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
if let ScopeDef::MacroDef(macro_def) = def { if let ScopeDef::MacroDef(macro_def) = def {
acc.add_macro(ctx, Some(name.to_string()), macro_def); acc.add_macro(ctx, Some(name.to_string()), macro_def);
} }
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
acc.add_resolution(ctx, name.to_string(), &def);
}
} }
} }
return; return;
@ -614,19 +617,20 @@ fn main() { let _ = crate::$0 }
} }
#[test] #[test]
fn completes_qualified_macros_in_impl() { fn completes_in_assoc_item_list() {
check( check(
r#" r#"
#[macro_export] #[macro_export]
macro_rules! foo { () => {} } macro_rules! foo { () => {} }
mod bar {}
struct MyStruct {} struct MyStruct {}
impl MyStruct { impl MyStruct {
crate::$0 crate::$0
} }
"#, "#,
expect![[r##" expect![[r##"
md bar
ma foo! #[macro_export] macro_rules! foo ma foo! #[macro_export] macro_rules! foo
"##]], "##]],
); );

View file

@ -17,6 +17,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
if let ScopeDef::MacroDef(macro_def) = def { if let ScopeDef::MacroDef(macro_def) = def {
acc.add_macro(ctx, Some(name.to_string()), macro_def); acc.add_macro(ctx, Some(name.to_string()), macro_def);
} }
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
acc.add_resolution(ctx, name.to_string(), &def);
}
}); });
return; return;
} }
@ -672,17 +675,19 @@ impl My$0
} }
#[test] #[test]
fn only_completes_macros_in_assoc_item_list() { fn completes_in_assoc_item_list() {
check( check(
r#" r#"
struct MyStruct {}
macro_rules! foo {} macro_rules! foo {}
mod bar {}
struct MyStruct {}
impl MyStruct { impl MyStruct {
$0 $0
} }
"#, "#,
expect![[r#" expect![[r#"
md bar
ma foo! macro_rules! foo ma foo! macro_rules! foo
"#]], "#]],
) )

View file

@ -62,7 +62,6 @@ pub(crate) fn determine_location(tok: SyntaxToken) -> Option<ImmediateLocation>
ast::SourceFile(_it) => ImmediateLocation::ItemList, ast::SourceFile(_it) => ImmediateLocation::ItemList,
ast::ItemList(_it) => ImmediateLocation::ItemList, ast::ItemList(_it) => ImmediateLocation::ItemList,
ast::RefExpr(_it) => ImmediateLocation::RefExpr, ast::RefExpr(_it) => ImmediateLocation::RefExpr,
ast::RefPat(_it) => ImmediateLocation::RefExpr,
ast::RecordField(_it) => ImmediateLocation::RecordField, ast::RecordField(_it) => ImmediateLocation::RecordField,
ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) { ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) {
Some(IMPL) => ImmediateLocation::Impl, Some(IMPL) => ImmediateLocation::Impl,