Skip to content

Commit fb7105a

Browse files
committed
Add config setting for self-on-the-fly
1 parent 4507382 commit fb7105a

File tree

10 files changed

+27
-2
lines changed

10 files changed

+27
-2
lines changed

crates/ide_completion/src/completions/dot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
3030
}
3131

3232
fn 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 {
3434
return;
3535
}
3636
ctx.scope.process_all_names(&mut |name, def| {

crates/ide_completion/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap};
1010
pub struct CompletionConfig {
1111
pub enable_postfix_completions: bool,
1212
pub enable_imports_on_the_fly: bool,
13+
pub enable_self_on_the_fly: bool,
1314
pub add_call_parenthesis: bool,
1415
pub add_call_argument_snippets: bool,
1516
pub snippet_cap: Option<SnippetCap>,

crates/ide_completion/src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a> Render<'a> {
139139
let mut item = CompletionItem::new(
140140
CompletionKind::Reference,
141141
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)),
143143
);
144144
item.kind(SymbolKind::Field)
145145
.detail(ty.display(self.ctx.db()).to_string())

crates/ide_completion/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
1919
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
2020
enable_postfix_completions: true,
2121
enable_imports_on_the_fly: true,
22+
enable_self_on_the_fly: true,
2223
add_call_parenthesis: true,
2324
add_call_argument_snippets: true,
2425
snippet_cap: SnippetCap::new(true),

crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ config_data! {
100100
/// Toggles the additional completions that automatically add imports when completed.
101101
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
102102
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",
103106

104107
/// Whether to show native rust-analyzer diagnostics.
105108
diagnostics_enable: bool = "true",
@@ -666,6 +669,7 @@ impl Config {
666669
enable_postfix_completions: self.data.completion_postfix_enable,
667670
enable_imports_on_the_fly: self.data.completion_autoimport_enable
668671
&& completion_item_edit_resolve(&self.caps),
672+
enable_self_on_the_fly: self.data.completion_autoself_enable,
669673
add_call_parenthesis: self.data.completion_addCallParenthesis,
670674
add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
671675
insert_use: self.insert_use_config(),

crates/rust-analyzer/src/integrated_benchmarks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ fn integrated_completion_benchmark() {
132132
let config = CompletionConfig {
133133
enable_postfix_completions: true,
134134
enable_imports_on_the_fly: true,
135+
enable_self_on_the_fly: true,
135136
add_call_parenthesis: true,
136137
add_call_argument_snippets: true,
137138
snippet_cap: SnippetCap::new(true),
@@ -166,6 +167,7 @@ fn integrated_completion_benchmark() {
166167
let config = CompletionConfig {
167168
enable_postfix_completions: true,
168169
enable_imports_on_the_fly: true,
170+
enable_self_on_the_fly: true,
169171
add_call_parenthesis: true,
170172
add_call_argument_snippets: true,
171173
snippet_cap: SnippetCap::new(true),

crates/rust-analyzer/src/to_proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ mod tests {
11781178
&ide::CompletionConfig {
11791179
enable_postfix_completions: true,
11801180
enable_imports_on_the_fly: true,
1181+
enable_self_on_the_fly: true,
11811182
add_call_parenthesis: true,
11821183
add_call_argument_snippets: true,
11831184
snippet_cap: SnippetCap::new(true),

docs/dev/architecture.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,8 @@ This is cheap enough to enable in production.
447447

448448
Similarly, we save live object counting (`RA_COUNT=1`).
449449
It is not cheap enough to enable in prod, and this is a bug which should be fixed.
450+
451+
### Configurability
452+
453+
rust-analyzer strives to be as configurable as possible while offering reasonable defaults where no configuration exists yet.
454+
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.

docs/user/generated_config.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
136136
Toggles the additional completions that automatically add imports when completed.
137137
Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
138138
--
139+
[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`)::
140+
+
141+
--
142+
Toggles the additional completions that automatically show method calls and field accesses
143+
with `self` prefixed to them when inside a method.
144+
--
139145
[[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
140146
+
141147
--

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@
572572
"default": true,
573573
"type": "boolean"
574574
},
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+
},
575580
"rust-analyzer.diagnostics.enable": {
576581
"markdownDescription": "Whether to show native rust-analyzer diagnostics.",
577582
"default": true,

0 commit comments

Comments
 (0)