fix: resolve each definition when a use statement imports multiple items#22655
fix: resolve each definition when a use statement imports multiple items#22655Hmikihiro wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
When it finds definitions on a NameRef of a use statement, it returns multiple definitions as NameRefClass::DefinitionPerNs. Each definition is registered in the vector of definiotns.
In goto_definition, hover and highlights, It show multiple items in use statement.
Fixes rust-lang#22632
AI-disclosure: Antigravity
There was a problem hiding this comment.
The right way, I'm pretty sure about that, is not to do add a different variant to NameRefClass. What it is - I don't know. It might be changing Definition to include all namespaces, or returning multiple NameRefClasses from classify(), or having a new method, or something else entirely.
Also note that @dfireBird has already claimed #19421, which is highly related (although not the same), you might want to discuss their approach with them.
| macro_ns: macros(), | ||
| let type_ns = types().or_else(items); | ||
| if let Some(PathResolution::Def(ModuleDef::Module(module))) = type_ns | ||
| && module.is_crate_root(db) |
There was a problem hiding this comment.
That if is definitely incorrect. Why did you add it?
There was a problem hiding this comment.
Sorry. I think that fix was just a stopgap measure. The issue is that the system is searching for and finding the value inside the crate at the same level as foo, which represents the crate, so I'll look into it and fix that part as well.
rust-analyzer/crates/ide/src/hover/tests.rs
Lines 6869 to 6887 in ef691be
*foo*
```rust
extern crate foo
```
---
```rust
foo
```
```rust
pub fn foo()
```
There was a problem hiding this comment.
This is interesting. In analysis we won't resolve this to the function because it wasn't recorded yet in the module, but in IDE resolution we have everything recorded.
I don't know if we can solve this, but I don't think this justifies this if. It can also lead to wrong resolution, e.g.:
use crate as foo;
fn foo() {}
mod bar {
use super::foo$0;
}There was a problem hiding this comment.
Although, how do we even get to this function in this case? It should call resolve_hir_path_qualifier() instead.
|
☔ The latest upstream changes (possibly #22673) made this pull request unmergeable. Please resolve the merge conflicts. |
When it finds definitions on a NameRef of a use statement, it returns multiple definitions as NameRefClass::DefinitionPerNs. Each definition is registered in the vector of definiotns.
In goto_definition, hover and highlights, It show multiple items in use statement.
Fixes #22632
AI-disclosure: Antigravity