about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2021-05-30 16:41:33 +0200
committerLukas Wirth <lukastw97@gmail.com>2021-05-31 15:14:56 +0200
commitfb7105a5801ab1d0ede830cd53bbc3ccbf0b5e2c (patch)
tree958c7a8548dcc6cfce25ace53476183d73b1460d
parent4507382f2e66cd0e6498228bfdffb16769063b0f (diff)
downloadrust-fb7105a5801ab1d0ede830cd53bbc3ccbf0b5e2c.tar.gz
rust-fb7105a5801ab1d0ede830cd53bbc3ccbf0b5e2c.zip
Add config setting for self-on-the-fly
-rw-r--r--crates/ide_completion/src/completions/dot.rs2
-rw-r--r--crates/ide_completion/src/config.rs1
-rw-r--r--crates/ide_completion/src/render.rs2
-rw-r--r--crates/ide_completion/src/test_utils.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs2
-rw-r--r--crates/rust-analyzer/src/to_proto.rs1
-rw-r--r--docs/dev/architecture.md5
-rw-r--r--docs/user/generated_config.adoc6
-rw-r--r--editors/code/package.json5
10 files changed, 27 insertions, 2 deletions
diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs
index 886251639e7..302c9ccbd36 100644
--- a/crates/ide_completion/src/completions/dot.rs
+++ b/crates/ide_completion/src/completions/dot.rs
@@ -30,7 +30,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
 }
 
 fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
-    if !ctx.is_trivial_path {
+    if !ctx.is_trivial_path || !ctx.config.enable_self_on_the_fly {
         return;
     }
     ctx.scope.process_all_names(&mut |name, def| {
diff --git a/crates/ide_completion/src/config.rs b/crates/ide_completion/src/config.rs
index d70ed6c1cde..c300ce887be 100644
--- a/crates/ide_completion/src/config.rs
+++ b/crates/ide_completion/src/config.rs
@@ -10,6 +10,7 @@ use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap};
 pub struct CompletionConfig {
     pub enable_postfix_completions: bool,
     pub enable_imports_on_the_fly: bool,
+    pub enable_self_on_the_fly: bool,
     pub add_call_parenthesis: bool,
     pub add_call_argument_snippets: bool,
     pub snippet_cap: Option<SnippetCap>,
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 97dd528515c..a49a6071127 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -139,7 +139,7 @@ impl<'a> Render<'a> {
         let mut item = CompletionItem::new(
             CompletionKind::Reference,
             self.ctx.source_range(),
-            receiver.map_or_else(|| name.to_string(), |receiver| format!("{}.{}", receiver, name)),
+            receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)),
         );
         item.kind(SymbolKind::Field)
             .detail(ty.display(self.ctx.db()).to_string())
diff --git a/crates/ide_completion/src/test_utils.rs b/crates/ide_completion/src/test_utils.rs
index 93c7c872ccf..b0a4b2026b0 100644
--- a/crates/ide_completion/src/test_utils.rs
+++ b/crates/ide_completion/src/test_utils.rs
@@ -19,6 +19,7 @@ use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
 pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
     enable_postfix_completions: true,
     enable_imports_on_the_fly: true,
+    enable_self_on_the_fly: true,
     add_call_parenthesis: true,
     add_call_argument_snippets: true,
     snippet_cap: SnippetCap::new(true),
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index a67b0bb2574..ae78fd4f612 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -100,6 +100,9 @@ config_data! {
         /// 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.
         completion_autoimport_enable: bool       = "true",
+        /// Toggles the additional completions that automatically show method calls and field accesses
+        /// with `self` prefixed to them when inside a method.
+        completion_autoself_enable: bool       = "true",
 
         /// Whether to show native rust-analyzer diagnostics.
         diagnostics_enable: bool                = "true",
@@ -666,6 +669,7 @@ impl Config {
             enable_postfix_completions: self.data.completion_postfix_enable,
             enable_imports_on_the_fly: self.data.completion_autoimport_enable
                 && completion_item_edit_resolve(&self.caps),
+            enable_self_on_the_fly: self.data.completion_autoself_enable,
             add_call_parenthesis: self.data.completion_addCallParenthesis,
             add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
             insert_use: self.insert_use_config(),
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 781073fe5b8..ec36a5f5c00 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -132,6 +132,7 @@ fn integrated_completion_benchmark() {
         let config = CompletionConfig {
             enable_postfix_completions: true,
             enable_imports_on_the_fly: true,
+            enable_self_on_the_fly: true,
             add_call_parenthesis: true,
             add_call_argument_snippets: true,
             snippet_cap: SnippetCap::new(true),
@@ -166,6 +167,7 @@ fn integrated_completion_benchmark() {
         let config = CompletionConfig {
             enable_postfix_completions: true,
             enable_imports_on_the_fly: true,
+            enable_self_on_the_fly: true,
             add_call_parenthesis: true,
             add_call_argument_snippets: true,
             snippet_cap: SnippetCap::new(true),
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index f5c8535a294..2b2ef2c60c3 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -1178,6 +1178,7 @@ mod tests {
                 &ide::CompletionConfig {
                     enable_postfix_completions: true,
                     enable_imports_on_the_fly: true,
+                    enable_self_on_the_fly: true,
                     add_call_parenthesis: true,
                     add_call_argument_snippets: true,
                     snippet_cap: SnippetCap::new(true),
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index 39edf9e19c6..2624069a5cc 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -447,3 +447,8 @@ This is cheap enough to enable in production.
 
 Similarly, we save live object counting (`RA_COUNT=1`).
 It is not cheap enough to enable in prod, and this is a bug which should be fixed.
+
+### Configurability
+
+rust-analyzer strives to be as configurable as possible while offering reasonable defaults where no configuration exists yet.
+There will always be features that some people find more annoying than helpful, so giving the users the ability to tweak or disable these is a big part of offering a good user experience.
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 4a5782a57e0..dbd9a3503b5 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -136,6 +136,12 @@ Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
 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.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`)::
++
+--
+Toggles the additional completions that automatically show method calls and field accesses
+with `self` prefixed to them when inside a method.
+--
 [[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
 +
 --
diff --git a/editors/code/package.json b/editors/code/package.json
index 5b80cc1f9d9..42a06e13744 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -572,6 +572,11 @@
                     "default": true,
                     "type": "boolean"
                 },
+                "rust-analyzer.completion.autoself.enable": {
+                    "markdownDescription": "Toggles the additional completions that automatically show method calls and field accesses\nwith `self` prefixed to them when inside a method.",
+                    "default": true,
+                    "type": "boolean"
+                },
                 "rust-analyzer.diagnostics.enable": {
                     "markdownDescription": "Whether to show native rust-analyzer diagnostics.",
                     "default": true,