aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 886251639..302c9ccbd 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) {
30} 30}
31 31
32fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) { 32fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
33 if !ctx.is_trivial_path { 33 if !ctx.is_trivial_path || !ctx.config.enable_self_on_the_fly {
34 return; 34 return;
35 } 35 }
36 ctx.scope.process_all_names(&mut |name, def| { 36 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 d70ed6c1c..c300ce887 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};
10pub struct CompletionConfig { 10pub struct CompletionConfig {
11 pub enable_postfix_completions: bool, 11 pub enable_postfix_completions: bool,
12 pub enable_imports_on_the_fly: bool, 12 pub enable_imports_on_the_fly: bool,
13 pub enable_self_on_the_fly: bool,
13 pub add_call_parenthesis: bool, 14 pub add_call_parenthesis: bool,
14 pub add_call_argument_snippets: bool, 15 pub add_call_argument_snippets: bool,
15 pub snippet_cap: Option<SnippetCap>, 16 pub snippet_cap: Option<SnippetCap>,
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 97dd52851..a49a60711 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -139,7 +139,7 @@ impl<'a> Render<'a> {
139 let mut item = CompletionItem::new( 139 let mut item = CompletionItem::new(
140 CompletionKind::Reference, 140 CompletionKind::Reference,
141 self.ctx.source_range(), 141 self.ctx.source_range(),
142 receiver.map_or_else(|| name.to_string(), |receiver| format!("{}.{}", receiver, name)), 142 receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)),
143 ); 143 );
144 item.kind(SymbolKind::Field) 144 item.kind(SymbolKind::Field)
145 .detail(ty.display(self.ctx.db()).to_string()) 145 .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 93c7c872c..b0a4b2026 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};
19pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig { 19pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
20 enable_postfix_completions: true, 20 enable_postfix_completions: true,
21 enable_imports_on_the_fly: true, 21 enable_imports_on_the_fly: true,
22 enable_self_on_the_fly: true,
22 add_call_parenthesis: true, 23 add_call_parenthesis: true,
23 add_call_argument_snippets: true, 24 add_call_argument_snippets: true,
24 snippet_cap: SnippetCap::new(true), 25 snippet_cap: SnippetCap::new(true),
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index a67b0bb25..ae78fd4f6 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -100,6 +100,9 @@ config_data! {
100 /// Toggles the additional completions that automatically add imports when completed. 100 /// Toggles the additional completions that automatically add imports when completed.
101 /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. 101 /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
102 completion_autoimport_enable: bool = "true", 102 completion_autoimport_enable: bool = "true",
103 /// Toggles the additional completions that automatically show method calls and field accesses
104 /// with `self` prefixed to them when inside a method.
105 completion_autoself_enable: bool = "true",
103 106
104 /// Whether to show native rust-analyzer diagnostics. 107 /// Whether to show native rust-analyzer diagnostics.
105 diagnostics_enable: bool = "true", 108 diagnostics_enable: bool = "true",
@@ -666,6 +669,7 @@ impl Config {
666 enable_postfix_completions: self.data.completion_postfix_enable, 669 enable_postfix_completions: self.data.completion_postfix_enable,
667 enable_imports_on_the_fly: self.data.completion_autoimport_enable 670 enable_imports_on_the_fly: self.data.completion_autoimport_enable
668 && completion_item_edit_resolve(&self.caps), 671 && completion_item_edit_resolve(&self.caps),
672 enable_self_on_the_fly: self.data.completion_autoself_enable,
669 add_call_parenthesis: self.data.completion_addCallParenthesis, 673 add_call_parenthesis: self.data.completion_addCallParenthesis,
670 add_call_argument_snippets: self.data.completion_addCallArgumentSnippets, 674 add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
671 insert_use: self.insert_use_config(), 675 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 781073fe5..ec36a5f5c 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() {
132 let config = CompletionConfig { 132 let config = CompletionConfig {
133 enable_postfix_completions: true, 133 enable_postfix_completions: true,
134 enable_imports_on_the_fly: true, 134 enable_imports_on_the_fly: true,
135 enable_self_on_the_fly: true,
135 add_call_parenthesis: true, 136 add_call_parenthesis: true,
136 add_call_argument_snippets: true, 137 add_call_argument_snippets: true,
137 snippet_cap: SnippetCap::new(true), 138 snippet_cap: SnippetCap::new(true),
@@ -166,6 +167,7 @@ fn integrated_completion_benchmark() {
166 let config = CompletionConfig { 167 let config = CompletionConfig {
167 enable_postfix_completions: true, 168 enable_postfix_completions: true,
168 enable_imports_on_the_fly: true, 169 enable_imports_on_the_fly: true,
170 enable_self_on_the_fly: true,
169 add_call_parenthesis: true, 171 add_call_parenthesis: true,
170 add_call_argument_snippets: true, 172 add_call_argument_snippets: true,
171 snippet_cap: SnippetCap::new(true), 173 snippet_cap: SnippetCap::new(true),
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index f5c8535a2..2b2ef2c60 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -1178,6 +1178,7 @@ mod tests {
1178 &ide::CompletionConfig { 1178 &ide::CompletionConfig {
1179 enable_postfix_completions: true, 1179 enable_postfix_completions: true,
1180 enable_imports_on_the_fly: true, 1180 enable_imports_on_the_fly: true,
1181 enable_self_on_the_fly: true,
1181 add_call_parenthesis: true, 1182 add_call_parenthesis: true,
1182 add_call_argument_snippets: true, 1183 add_call_argument_snippets: true,
1183 snippet_cap: SnippetCap::new(true), 1184 snippet_cap: SnippetCap::new(true),
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index 39edf9e19..2624069a5 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -447,3 +447,8 @@ This is cheap enough to enable in production.
447 447
448Similarly, we save live object counting (`RA_COUNT=1`). 448Similarly, we save live object counting (`RA_COUNT=1`).
449It is not cheap enough to enable in prod, and this is a bug which should be fixed. 449It is not cheap enough to enable in prod, and this is a bug which should be fixed.
450
451### Configurability
452
453rust-analyzer strives to be as configurable as possible while offering reasonable defaults where no configuration exists yet.
454There 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 4a5782a57..dbd9a3503 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.
136Toggles the additional completions that automatically add imports when completed. 136Toggles the additional completions that automatically add imports when completed.
137Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled. 137Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
138-- 138--
139[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`)::
140+
141--
142Toggles the additional completions that automatically show method calls and field accesses
143with `self` prefixed to them when inside a method.
144--
139[[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`):: 145[[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
140+ 146+
141-- 147--
diff --git a/editors/code/package.json b/editors/code/package.json
index 5b80cc1f9..42a06e137 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -572,6 +572,11 @@
572 "default": true, 572 "default": true,
573 "type": "boolean" 573 "type": "boolean"
574 }, 574 },
575 "rust-analyzer.completion.autoself.enable": {
576 "markdownDescription": "Toggles the additional completions that automatically show method calls and field accesses\nwith `self` prefixed to them when inside a method.",
577 "default": true,
578 "type": "boolean"
579 },
575 "rust-analyzer.diagnostics.enable": { 580 "rust-analyzer.diagnostics.enable": {
576 "markdownDescription": "Whether to show native rust-analyzer diagnostics.", 581 "markdownDescription": "Whether to show native rust-analyzer diagnostics.",
577 "default": true, 582 "default": true,