Reduce the default autoimport exclusion list

This commit is contained in:
Lukas Wirth 2025-01-01 14:09:05 +01:00
parent a02a1afc92
commit 45954ebaa4
5 changed files with 90 additions and 186 deletions

View file

@ -354,13 +354,6 @@ impl ItemScope {
.chain(self.unnamed_trait_imports.keys().copied())
}
pub fn trait_by_name(&self, name: &Name) -> Option<TraitId> {
self.types.get(name).and_then(|def| match def.def {
ModuleDefId::TraitId(it) => Some(it),
_ => None,
})
}
pub(crate) fn resolutions(&self) -> impl Iterator<Item = (Option<Name>, PerNs)> + '_ {
self.entries().map(|(name, res)| (Some(name.clone()), res)).chain(
self.unnamed_trait_imports.iter().map(|(tr, trait_)| {

View file

@ -1430,19 +1430,22 @@ fn foo() {
}
"#,
expect![[r#"
me inherent() fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
me bar() (as ExcludedTrait) fn(&self)
me baz() (as ExcludedTrait) fn(&self)
me foo() (as ExcludedTrait) fn(&self)
me inherent() fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
"#]],
);
}
@ -1468,18 +1471,18 @@ fn foo(v: &dyn ExcludedTrait) {
me bar() (as ExcludedTrait) fn(&self)
me baz() (as ExcludedTrait) fn(&self)
me foo() (as ExcludedTrait) fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
sn unsafe unsafe {}
"#]],
);
check_with_config(
@ -1501,18 +1504,18 @@ fn foo(v: impl ExcludedTrait) {
me bar() (as ExcludedTrait) fn(&self)
me baz() (as ExcludedTrait) fn(&self)
me foo() (as ExcludedTrait) fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
sn unsafe unsafe {}
"#]],
);
check_with_config(
@ -1534,18 +1537,18 @@ fn foo<T: ExcludedTrait>(v: T) {
me bar() (as ExcludedTrait) fn(&self)
me baz() (as ExcludedTrait) fn(&self)
me foo() (as ExcludedTrait) fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
sn unsafe unsafe {}
"#]],
);
}
@ -1578,19 +1581,22 @@ fn foo() {
}
"#,
expect![[r#"
me inherent() fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
me bar() (use module2::ExcludedTrait) fn(&self)
me baz() (use module2::ExcludedTrait) fn(&self)
me foo() (use module2::ExcludedTrait) fn(&self)
me inherent() fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
"#]],
);
}
@ -1623,19 +1629,22 @@ fn foo() {
}
"#,
expect![[r#"
me inherent() fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
me bar() (use module2::ExcludedTrait) fn(&self)
me baz() (use module2::ExcludedTrait) fn(&self)
me foo() (use module2::ExcludedTrait) fn(&self)
me inherent() fn(&self)
sn box Box::new(expr)
sn call function(expr)
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
"#]],
);
}
@ -1663,8 +1672,11 @@ fn foo() {
}
"#,
expect![[r#"
me inherent() fn(&self)
"#]],
me bar() (as ExcludedTrait) fn(&self)
me baz() (as ExcludedTrait) fn(&self)
me foo() (as ExcludedTrait) fn(&self)
me inherent() fn(&self)
"#]],
);
}

View file

@ -442,50 +442,13 @@ config_data! {
completion_autoimport_enable: bool = true,
/// A list of full paths to traits to exclude from flyimport.
///
/// Traits in this list won't be suggested to be imported by flyimport for their methods. Methods from them won't be available in flyimport completion. They will still be available if in scope.
///
/// Note that the trait themselves can still be suggested by flyimport.
/// Traits in this list won't have their methods suggested in completions unless the trait
/// is in scope.
///
/// This setting also inherits `#rust-analyzer.completion.excludeTraits#`.
///
/// This setting defaults to:
///
/// - [`core::borrow::Borrow`](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html)
/// - [`core::borrow::BorrowMut`](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html)
/// - [`core::cmp::PartialEq`](https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html)
/// - All operator traits (in [`core::ops`](https://doc.rust-lang.org/nightly/core/ops))
///
/// Note that if you override this setting, those traits won't be automatically inserted, so you may want to insert them manually.
completion_autoimport_excludeTraits: Vec<String> = vec![
"core::borrow::Borrow".to_owned(),
"core::borrow::BorrowMut".to_owned(),
"core::cmp::PartialEq".to_owned(),
"core::ops::Add".to_owned(),
"core::ops::AddAssign".to_owned(),
"core::ops::BitAnd".to_owned(),
"core::ops::BitAndAssign".to_owned(),
"core::ops::BitOr".to_owned(),
"core::ops::BitOrAssign".to_owned(),
"core::ops::BitXor".to_owned(),
"core::ops::BitXorAssign".to_owned(),
"core::ops::Div".to_owned(),
"core::ops::DivAssign".to_owned(),
"core::ops::Mul".to_owned(),
"core::ops::MulAssign".to_owned(),
"core::ops::Rem".to_owned(),
"core::ops::RemAssign".to_owned(),
"core::ops::Shl".to_owned(),
"core::ops::ShlAssign".to_owned(),
"core::ops::Shr".to_owned(),
"core::ops::ShrAssign".to_owned(),
"core::ops::Sub".to_owned(),
"core::ops::SubAssign".to_owned(),
"core::ops::Neg".to_owned(),
"core::ops::Not".to_owned(),
"core::ops::Index".to_owned(),
"core::ops::IndexMut".to_owned(),
"core::ops::Deref".to_owned(),
"core::ops::DerefMut".to_owned(),
],
/// Toggles the additional completions that automatically show method calls and field accesses
/// with `self` prefixed to them when inside a method.

View file

@ -293,53 +293,16 @@ Default:
----
[
"core::borrow::Borrow",
"core::borrow::BorrowMut",
"core::cmp::PartialEq",
"core::ops::Add",
"core::ops::AddAssign",
"core::ops::BitAnd",
"core::ops::BitAndAssign",
"core::ops::BitOr",
"core::ops::BitOrAssign",
"core::ops::BitXor",
"core::ops::BitXorAssign",
"core::ops::Div",
"core::ops::DivAssign",
"core::ops::Mul",
"core::ops::MulAssign",
"core::ops::Rem",
"core::ops::RemAssign",
"core::ops::Shl",
"core::ops::ShlAssign",
"core::ops::Shr",
"core::ops::ShrAssign",
"core::ops::Sub",
"core::ops::SubAssign",
"core::ops::Neg",
"core::ops::Not",
"core::ops::Index",
"core::ops::IndexMut",
"core::ops::Deref",
"core::ops::DerefMut"
"core::borrow::BorrowMut"
]
----
A list of full paths to traits to exclude from flyimport.
Traits in this list won't be suggested to be imported by flyimport for their methods. Methods from them won't be available in flyimport completion. They will still be available if in scope.
Note that the trait themselves can still be suggested by flyimport.
Traits in this list won't have their methods suggested in completions unless the trait
is in scope.
This setting also inherits `#rust-analyzer.completion.excludeTraits#`.
This setting defaults to:
- [`core::borrow::Borrow`](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html)
- [`core::borrow::BorrowMut`](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html)
- [`core::cmp::PartialEq`](https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html)
- All operator traits (in [`core::ops`](https://doc.rust-lang.org/nightly/core/ops))
Note that if you override this setting, those traits won't be automatically inserted, so you may want to insert them manually.
--
[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`)::
+

View file

@ -1143,37 +1143,10 @@
"title": "completion",
"properties": {
"rust-analyzer.completion.autoimport.excludeTraits": {
"markdownDescription": "A list of full paths to traits to exclude from flyimport.\n\nTraits in this list won't be suggested to be imported by flyimport for their methods. Methods from them won't be available in flyimport completion. They will still be available if in scope.\n\nNote that the trait themselves can still be suggested by flyimport.\n\nThis setting also inherits `#rust-analyzer.completion.excludeTraits#`.\n\nThis setting defaults to:\n\n - [`core::borrow::Borrow`](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html)\n - [`core::borrow::BorrowMut`](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html)\n - [`core::cmp::PartialEq`](https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html)\n - All operator traits (in [`core::ops`](https://doc.rust-lang.org/nightly/core/ops))\n\nNote that if you override this setting, those traits won't be automatically inserted, so you may want to insert them manually.",
"markdownDescription": "A list of full paths to traits to exclude from flyimport.\n\nTraits in this list won't have their methods suggested in completions unless the trait\nis in scope.\n\nThis setting also inherits `#rust-analyzer.completion.excludeTraits#`.",
"default": [
"core::borrow::Borrow",
"core::borrow::BorrowMut",
"core::cmp::PartialEq",
"core::ops::Add",
"core::ops::AddAssign",
"core::ops::BitAnd",
"core::ops::BitAndAssign",
"core::ops::BitOr",
"core::ops::BitOrAssign",
"core::ops::BitXor",
"core::ops::BitXorAssign",
"core::ops::Div",
"core::ops::DivAssign",
"core::ops::Mul",
"core::ops::MulAssign",
"core::ops::Rem",
"core::ops::RemAssign",
"core::ops::Shl",
"core::ops::ShlAssign",
"core::ops::Shr",
"core::ops::ShrAssign",
"core::ops::Sub",
"core::ops::SubAssign",
"core::ops::Neg",
"core::ops::Not",
"core::ops::Index",
"core::ops::IndexMut",
"core::ops::Deref",
"core::ops::DerefMut"
"core::borrow::BorrowMut"
],
"type": "array",
"items": {