Fix IDE resolution of use inside a body

We stopped the expression search too early because `use` is an item.
This commit is contained in:
Chayim Refael Friedman 2025-02-04 18:30:50 +02:00
parent 1ba7a38e4f
commit 54670912da
2 changed files with 23 additions and 1 deletions

View file

@ -1252,7 +1252,11 @@ fn scope_for(
node: InFile<&SyntaxNode>,
) -> Option<ScopeId> {
node.ancestors_with_macros(db.upcast())
.take_while(|it| !ast::Item::can_cast(it.kind()) || ast::MacroCall::can_cast(it.kind()))
.take_while(|it| {
!ast::Item::can_cast(it.kind())
|| ast::MacroCall::can_cast(it.kind())
|| ast::Use::can_cast(it.kind())
})
.filter_map(|it| it.map(ast::Expr::cast).transpose())
.filter_map(|it| source_map.node_expr(it.as_ref())?.as_expr())
.find_map(|it| scopes.scope_for(it))

View file

@ -3272,4 +3272,22 @@ fn f() {
"#,
);
}
#[test]
fn use_inside_body() {
check(
r#"
fn main() {
mod nice_module {
pub(super) struct NiceStruct;
// ^^^^^^^^^^
}
use nice_module::NiceStruct$0;
let _ = NiceStruct;
}
"#,
);
}
}