about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/docs
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2024-09-24 19:24:15 +0300
committerLukas Wirth <lukastw97@gmail.com>2025-01-01 13:49:35 +0100
commitbd6ea14002949c2b2fdf9ec51cce3634b7a15147 (patch)
tree27411f1c1d0e0ef51f52ebf114ab1e49c7153694 /src/tools/rust-analyzer/docs
parent88e630b8592ecc9df82bf568160df2e064df35e5 (diff)
Allow excluding specific traits from completion
To be accurate, only their methods are excluded, the trait themselves are still available.

I also excluded a bunch of std traits by default. Some less opinionated, like `AsRef`, which should never be used directly except in generic scenarios (and won't be excluded there), some more opinionated, like the ops traits, which I know some users sometimes want to use directly. Either way it's configurable.

It should be pretty easy to extend support to excluding only specific methods, but I didn't do that currently.

Traits configured to be excluded are resolved in each completion request from scratch. If this proves too expensive, it is easy enough to cache them in the DB.
Diffstat (limited to 'src/tools/rust-analyzer/docs')
-rw-r--r--src/tools/rust-analyzer/docs/user/generated_config.adoc64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/docs/user/generated_config.adoc b/src/tools/rust-analyzer/docs/user/generated_config.adoc
index 5056c7d977c..27ade71b331 100644
--- a/src/tools/rust-analyzer/docs/user/generated_config.adoc
+++ b/src/tools/rust-analyzer/docs/user/generated_config.adoc
@@ -286,6 +286,61 @@ In `match` arms it completes a comma instead.
 Toggles the additional completions that automatically add imports when completed.
 Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
 --
+[[rust-analyzer.completion.autoimport.excludeTraits]]rust-analyzer.completion.autoimport.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"
+]
+----
+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.
+
+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`)::
 +
 --
@@ -297,6 +352,15 @@ with `self` prefixed to them when inside a method.
 --
 Whether to add parenthesis and argument snippets when completing function.
 --
+[[rust-analyzer.completion.excludeTraits]]rust-analyzer.completion.excludeTraits (default: `[]`)::
++
+--
+A list of full paths to traits to exclude from completion.
+
+Methods from these traits won't be completed, even if the trait is in scope. However, they will still be suggested on expressions whose type is `dyn Trait`, `impl Trait` or `T where T: Trait`.
+
+Note that the trait themselves can still be completed.
+--
 [[rust-analyzer.completion.fullFunctionSignatures.enable]]rust-analyzer.completion.fullFunctionSignatures.enable (default: `false`)::
 +
 --