Skip to content

Commit a2cc1d6

Browse files
bors[bot]Veykril
andauthored
Merge #11538
11538: feat: Make private editable completions configurable, disable by default r=Veykril a=Veykril Fixes #10253 Fixes #9885 This does disable these completions by default, as it seems that people find this behaviour surprising(due to other IDEs usually not doing this). Co-authored-by: Lukas Wirth <[email protected]>
2 parents 7096a0a + 2a7793d commit a2cc1d6

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

crates/ide_completion/src/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct CompletionConfig {
1313
pub enable_postfix_completions: bool,
1414
pub enable_imports_on_the_fly: bool,
1515
pub enable_self_on_the_fly: bool,
16+
pub enable_private_editable: bool,
1617
pub add_call_parenthesis: bool,
1718
pub add_call_argument_snippets: bool,
1819
pub snippet_cap: Option<SnippetCap>,

crates/ide_completion/src/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ impl<'a> CompletionContext<'a> {
360360
None => return Visible::No,
361361
};
362362
if !vis.is_visible_from(self.db, module.into()) {
363+
if !self.config.enable_private_editable {
364+
return Visible::No;
365+
}
363366
// If the definition location is editable, also show private items
364367
let root_file = defining_crate.root_file(self.db);
365368
let source_root_id = self.db.file_source_root(root_file);

crates/ide_completion/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
6464
enable_postfix_completions: true,
6565
enable_imports_on_the_fly: true,
6666
enable_self_on_the_fly: true,
67+
enable_private_editable: true,
6768
add_call_parenthesis: true,
6869
add_call_argument_snippets: true,
6970
snippet_cap: SnippetCap::new(true),

crates/rust-analyzer/src/config.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ config_data! {
161161
}
162162
}"#,
163163
/// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
164-
completion_postfix_enable: bool = "true",
164+
completion_postfix_enable: bool = "true",
165165
/// Toggles the additional completions that automatically add imports when completed.
166166
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
167167
completion_autoimport_enable: bool = "true",
168168
/// Toggles the additional completions that automatically show method calls and field accesses
169169
/// with `self` prefixed to them when inside a method.
170-
completion_autoself_enable: bool = "true",
170+
completion_autoself_enable: bool = "true",
171+
/// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
172+
completion_privateEditable_enable: bool = "false",
171173

172174
/// Whether to show native rust-analyzer diagnostics.
173175
diagnostics_enable: bool = "true",
@@ -875,6 +877,7 @@ impl Config {
875877
enable_imports_on_the_fly: self.data.completion_autoimport_enable
876878
&& completion_item_edit_resolve(&self.caps),
877879
enable_self_on_the_fly: self.data.completion_autoself_enable,
880+
enable_private_editable: self.data.completion_privateEditable_enable,
878881
add_call_parenthesis: self.data.completion_addCallParenthesis,
879882
add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
880883
insert_use: self.insert_use_config(),

crates/rust-analyzer/src/integrated_benchmarks.rs

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ fn integrated_completion_benchmark() {
134134
enable_postfix_completions: true,
135135
enable_imports_on_the_fly: true,
136136
enable_self_on_the_fly: true,
137+
enable_private_editable: true,
137138
add_call_parenthesis: true,
138139
add_call_argument_snippets: true,
139140
snippet_cap: SnippetCap::new(true),
@@ -171,6 +172,7 @@ fn integrated_completion_benchmark() {
171172
enable_postfix_completions: true,
172173
enable_imports_on_the_fly: true,
173174
enable_self_on_the_fly: true,
175+
enable_private_editable: true,
174176
add_call_parenthesis: true,
175177
add_call_argument_snippets: true,
176178
snippet_cap: SnippetCap::new(true),

docs/user/generated_config.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ Note that your client must specify the `additionalTextEdits` LSP client capabili
213213
Toggles the additional completions that automatically show method calls and field accesses
214214
with `self` prefixed to them when inside a method.
215215
--
216+
[[rust-analyzer.completion.privateEditable.enable]]rust-analyzer.completion.privateEditable.enable (default: `false`)::
217+
+
218+
--
219+
Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
220+
--
216221
[[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
217222
+
218223
--

editors/code/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@
643643
"default": true,
644644
"type": "boolean"
645645
},
646+
"rust-analyzer.completion.privateEditable.enable": {
647+
"markdownDescription": "Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.",
648+
"default": false,
649+
"type": "boolean"
650+
},
646651
"rust-analyzer.diagnostics.enable": {
647652
"markdownDescription": "Whether to show native rust-analyzer diagnostics.",
648653
"default": true,

0 commit comments

Comments
 (0)