fix: Goto implementation to impls inside blocks by ShoyuVanilla · Pull Request #...
source link: https://github.com/rust-lang/rust-analyzer/pull/16812
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
fix: Goto implementation to impls inside blocks #16812
Conversation
Contributor
Fixes #3739
added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label
Comment on lines
270 to 221
// 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); |
||
} |
||
} |
||
} |
||
} |
Contributor
Author
The logic is quite verbose, but I couldn't find any good ways that can probe into those blocks 🤔
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() { |
This test we cannot support due to performance reasons, see the main review message
} |
||
#[test] |
||
fn goto_implementation_in_nested_blocks_1() { |
This we can support
added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
labels
Contributor
Author
I'm seeking some performant implementation; is there any way to find |
Member
You can turn block expression ast nodes into blocks via (Note that will only yieldSome 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? |
Contributor
Author
Thank you! I'll look into that point 😄 |
Member
Thanks! |
Collaborator
☀️ Test successful - checks-actions |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No one assigned
None yet
No milestone
Successfully merging this pull request may close these issues.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK