Auto merge of #11988 - jonas-schievink:expand-glob, r=jonas-schievink

minor: reenable simplify glob import test
This commit is contained in:
bors 2022-04-14 11:03:02 +00:00
commit 4cee507d28

View file

@ -52,7 +52,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
let current_scope = ctx.sema.scope(&star.parent()?)?; let current_scope = ctx.sema.scope(&star.parent()?)?;
let current_module = current_scope.module(); let current_module = current_scope.module();
let refs_in_target = find_refs_in_mod(ctx, target_module, Some(current_module))?; let refs_in_target = find_refs_in_mod(ctx, target_module, current_module)?;
let imported_defs = find_imported_defs(ctx, star)?; let imported_defs = find_imported_defs(ctx, star)?;
let target = parent.either(|n| n.syntax().clone(), |n| n.syntax().clone()); let target = parent.either(|n| n.syntax().clone(), |n| n.syntax().clone());
@ -168,18 +168,12 @@ impl Refs {
} }
} }
fn find_refs_in_mod( fn find_refs_in_mod(ctx: &AssistContext, module: Module, visible_from: Module) -> Option<Refs> {
ctx: &AssistContext, if !is_mod_visible_from(ctx, module, visible_from) {
module: Module, return None;
visible_from: Option<Module>,
) -> Option<Refs> {
if let Some(from) = visible_from {
if !is_mod_visible_from(ctx, module, from) {
return None;
}
} }
let module_scope = module.scope(ctx.db(), visible_from); let module_scope = module.scope(ctx.db(), Some(visible_from));
let refs = module_scope.into_iter().filter_map(|(n, d)| Ref::from_scope_def(n, d)).collect(); let refs = module_scope.into_iter().filter_map(|(n, d)| Ref::from_scope_def(n, d)).collect();
Some(Refs(refs)) Some(Refs(refs))
} }
@ -729,37 +723,34 @@ fn qux(bar: Bar, baz: Baz) {
#[test] #[test]
fn expanding_glob_import_with_macro_defs() { fn expanding_glob_import_with_macro_defs() {
// FIXME: this is currently fails because `Definition::find_usages` ignores macros check_assist(
// https://github.com/rust-analyzer/rust-analyzer/issues/3484 expand_glob_import,
// r#"
// check_assist( //- /lib.rs crate:foo
// expand_glob_import, #[macro_export]
// r" macro_rules! bar {
// //- /lib.rs crate:foo () => ()
// #[macro_export] }
// macro_rules! bar {
// () => ()
// }
// pub fn baz() {} pub fn baz() {}
// //- /main.rs crate:main deps:foo //- /main.rs crate:main deps:foo
// use foo::*$0; use foo::*$0;
// fn main() { fn main() {
// bar!(); bar!();
// baz(); baz();
// } }
// ", "#,
// r" r#"
// use foo::{bar, baz}; use foo::{bar, baz};
// fn main() { fn main() {
// bar!(); bar!();
// baz(); baz();
// } }
// ", "#,
// ) );
} }
#[test] #[test]