New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Goto implementation to impls inside blocks #16812
Conversation
// Collect nested impls inside function bodies, etc. | ||
for (_, ns) in module_data.scope.entries() { | ||
for module in ns.types.iter().map(|t| t.0).chain(ns.values.iter().map(|t| t.0)) { | ||
let body: Option<DefWithBodyId> = match module { | ||
ModuleDefId::FunctionId(it) => Some(it.into()), | ||
ModuleDefId::EnumVariantId(it) => Some(it.into()), | ||
ModuleDefId::ConstId(it) => Some(it.into()), | ||
ModuleDefId::StaticId(it) => Some(it.into()), | ||
_ => None, | ||
}; | ||
if let Some(body) = body { | ||
let body = db.body(body); | ||
for (_, block_def_map) in body.blocks(db.upcast()) { | ||
Self::collect_def_map(db, map, &block_def_map, query_depth); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is quite verbose, but I couldn't find any good ways that can probe into those blocks 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We intentionally do not look into all blocks there are, as an IDE we try to be lazy and only analyze the crate structure on a global scale, which allows us to skip out on having to look into every body which would slow us down immensely. So supporting local impls like this isn't really possible.
So what we should do instead to make the first case work is have goto_implementation
look into the block defmaps of the ADT/trait definition and iterate those. We can query the relevant impls via the *_impls_in_block
queries (check for uses of those queries, that should show you how to use thisI think, if not just ask)
} | ||
|
||
#[test] | ||
fn goto_implementation_in_nested_blocks_2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test we cannot support due to performance reasons, see the main review message
} | ||
|
||
#[test] | ||
fn goto_implementation_in_nested_blocks_1() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This we can support
I'm seeking some performant implementation; is there any way to find |
You can turn block expression ast nodes into blocks via
Some for blocks that actually have local items or macro calls in them due to perf optimizations)
Though I tihnk it should be enough to just query the modules of the trait / ADT in question as those should be block modules if they are defined in blocks? |
Thank you! I'll look into that point 😄 |
c7fde4e
to
536c10b
Compare
536c10b
to
967a864
Compare
Thanks! |
☀️ Test successful - checks-actions |
Fixes #3739