diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-01-01 14:09:05 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2025-01-01 14:32:45 +0100 |
| commit | 13af22df98c790875d0a31f49c19cfd84e14d424 (patch) | |
| tree | 684c102d8a5160a9017914784e48a1a3eeec297d /src/tools | |
| parent | 528ed6bd011757b3e602f40c86ec0e79f613adcf (diff) | |
| download | rust-13af22df98c790875d0a31f49c19cfd84e14d424.tar.gz rust-13af22df98c790875d0a31f49c19cfd84e14d424.zip | |
Reduce the default autoimport exclusion list
Diffstat (limited to 'src/tools')
5 files changed, 90 insertions, 186 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs index f600efea9f2..2c3eb5c8e5e 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs @@ -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_)| { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs b/src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs index 6c95980507c..d1bbf1e8d0b 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/tests/expression.rs @@ -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) + "#]], ); } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index c53ca230409..b6678c12c70 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -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. diff --git a/src/tools/rust-analyzer/docs/user/generated_config.adoc b/src/tools/rust-analyzer/docs/user/generated_config.adoc index 27ade71b331..bce26f7dd74 100644 --- a/src/tools/rust-analyzer/docs/user/generated_config.adoc +++ b/src/tools/rust-analyzer/docs/user/generated_config.adoc @@ -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`):: + diff --git a/src/tools/rust-analyzer/editors/code/package.json b/src/tools/rust-analyzer/editors/code/package.json index a6e92838a06..31419a1942d 100644 --- a/src/tools/rust-analyzer/editors/code/package.json +++ b/src/tools/rust-analyzer/editors/code/package.json @@ -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": { |
