-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Test function imports replaced by module imports. #18464
Test function imports replaced by module imports. #18464
Conversation
Test for rust-lang#18347. The issue affects all code using import merging. When a function and a module share the same identifier, e.g. ```rust pub fn foo() {} pub mod foo { pub fn bar() {} } ``` rust analyzer often confuses the function with the module, generating invalid code.
I haven't been able to actually find a proper fix yet. I can't find a reliable way to tell the merging function whether an import is a module (and can be used for merging) or a function. I'm not sure if I manage to find a solution, so I'm sending a small PR with what I have. |
The IDE layer currently lacks being able to resolve something to multiple namespaces ( |
I'll close this for now due to inactivity, feel free to re-open if you try to tackle it again |
I'll give it another try.
I'm not sure I get this part. Why would we need Let's look at the rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs Lines 131 to 144 in 62dea27
My (limited) understanding is as follows. When the user selects the suggestion, we generate a new use ... tree
and then try to merge it into existing imports rust-analyzer/crates/ide-db/src/imports/insert_use.rs Lines 220 to 231 in 62dea27
ultimately ending at rust-analyzer/crates/ide-db/src/imports/merge_imports.rs Lines 87 to 118 in 62dea27
IIUC, the root cause is how the common prefix is calculated - the current logic is not
Would that do the trick? |
My point is that |
Mkay. |
Test for #18347.
The issue affects all code using import merging. When a function and a module share the same identifier, e.g.
rust analyzer often confuses the function with the module, generating invalid code.