Skip to content
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

Proper support for import aliases and attributes on imports #14079

Open
4 of 7 tasks
Veykril opened this issue Feb 2, 2023 · 1 comment
Open
4 of 7 tasks

Proper support for import aliases and attributes on imports #14079

Veykril opened this issue Feb 2, 2023 · 1 comment
Assignees
Labels
A-ide general IDE features C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) C-tracking-issue Category: tracking issue E-unknown It's unclear if the issue is E-hard or E-easy without digging in

Comments

@Veykril
Copy link
Member

Veykril commented Feb 2, 2023

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 Veykril added E-unknown It's unclear if the issue is E-hard or E-easy without digging in C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) C-tracking-issue Category: tracking issue labels Feb 2, 2023
@Veykril Veykril self-assigned this Jun 23, 2023
@Veykril Veykril mentioned this issue Jun 23, 2023
7 tasks
bors added a commit that referenced this issue Aug 2, 2023
Add ExternCrateDecl to HIR

Adding these doesn't really require much design effort as they represent a single import, unlike use trees which are one item that represent 0 or more imports.

We only resolve to this definition when actually resolving on the name or alias of an `extern crate name as alias` item, not usages yet as that requires far more changes that won't lead anywhere without giving it more thought. Nevertheless the changes slightly improve IDE things, an example being hover on the decl showing the merged doc comments for example.

cc #14079
bors added a commit that referenced this issue Aug 2, 2023
Name change Import to Use in hir-def, add unused placeholder variants for UseId

cc #14079
bors added a commit that referenced this issue Aug 9, 2023
internal: Record import source IDs

cc #14079
bors added a commit that referenced this issue Aug 17, 2023
internal: Record import origins in ItemScope and PerNS

This records the import items definitions come from in the module scope (as well as what an import resolves to in an ItemScope). It does ignore glob imports as thats a lot more work for little to no gain, glob imports act as if the importing items are "inlined" into the scope which suffices for almost all use cases I believe (to my knowledge, attributes on them have little effect).

There is still a lot of work needed to make this available to the IDE layer, but this lays out the ground work for havin IDE layer support.

cc #14079
kai-tock pushed a commit to kaibyao/fbkl-rust that referenced this issue Aug 21, 2023
@Veykril Veykril mentioned this issue Sep 11, 2023
5 tasks
@Veykril Veykril mentioned this issue Dec 4, 2023
3 tasks
@Veykril Veykril removed their assignment Dec 18, 2023
@Veykril
Copy link
Member Author

Veykril commented Dec 18, 2023

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

pub fn fully_resolve_import(&self, db: &dyn DefDatabase, mut import: ImportId) -> PerNs {

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) C-tracking-issue Category: tracking issue E-unknown It's unclear if the issue is E-hard or E-easy without digging in
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant