rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.13k stars 1.58k forks source link

Proper support for import aliases and attributes on imports #14079

Open Veykril opened 1 year ago

Veykril commented 1 year ago

We currently don't really support aliasing imports at all (aliases usually just break things or make them not work at all), likewise we kind of ignore most attributes on imports, like #[doc(hidden)] and similar things. We should make these work, though it's not clear how to tackle this.

some issues depending on this:

Veykril commented 9 months ago

So, what's roughly missing here to finish this issue up is the following:

Our Name{Ref} "classification" needs to be changed to accomodate for imports and extern crate declarations. I am unsure of the interface we want here, we might just want to have two APIs, one that returns Definitions as previously and another that returns Definitions and the Use/ExternCrateDecl that the Definition is coming from (unless it is defined in this scope). The relevant part for this is this file here https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-db/src/defs.rs

Then we just need to adjust all the IDE features that would want to care about the imports in that regard. For that we need to implement a way to step through the import chain. We already have a function to fully re-resolve an import here https://github.com/rust-lang/rust-analyzer/blob/91237a516b43abb1a81d33269615a42b3006d591/crates/hir-def/src/item_scope.rs#L162 Stepping through resolutions requires more effort though due to proper namespace handling and exposing a decent API for that in the IDE layer. Part of the task would be figuring that out.