-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Import assist for traits on unresolved trait item should offer importing anonymously #15684
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
Comments
What needs to be done is roughly the following:
Here we are fetching the ImportAssets which describe what kind of thing we want to import, it contains an ImportCandidate :rust-analyzer/crates/ide-db/src/imports/import_assets.rs Lines 26 to 37 in 8a23314
Leveraging that info we need to add additional import groups that will offer an rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs Lines 129 to 146 in 8a23314
To able to add the rust-analyzer/crates/ide-db/src/imports/insert_use.rs Lines 177 to 179 in 8a23314
It's probably easiest to split out the function into two, one for the previous behavior, one for the underscore behavior and then have those wrap a function that takes an extra param to not having to edit all the current call sites of the function. |
I'd like to have a try.
But how could we have a new function with an extra param without edit other call of |
oh maybe I got it. pub fn insert_use(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) {
insert_use_with_alias_option(scope, path, cfg, None);
}
pub fn insert_use_as_alias(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) {
let alias = ...;
insert_use_with_alias_option(scope, path, cfg, alias);
}
fn insert_use_with_alias_option(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig, alias: Option<ast::Rename>) {
...
let use_item = if alias.is_some() {
make::use_(None, make::use_tree(path.clone(), None, alias, false)).clone_for_update()
} else {
make::use_(None, make::use_tree(path.clone(), None, None, false)).clone_for_update()
};
...
} |
That is in the following case
We should show the general
Import `crate::foo::Foo`
as well as aImport `crate::foo::Foo as _`
that imports the trait without bringing the name of it into scope.The text was updated successfully, but these errors were encountered: