about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-25 21:17:24 +0000
committerGitHub <noreply@github.com>2022-02-25 21:17:24 +0000
commita2cc1d6b7b499d6b03436db7fc8053aea72f75ac (patch)
tree27da3e5f168503639ac9a4931299fbb4a677e28d
parent7096a0a14e5c01db9c992178e696fe100612bddf (diff)
parent2a7793d912bafef2d97c0e899262b94efe977543 (diff)
downloadrust-a2cc1d6b7b499d6b03436db7fc8053aea72f75ac.tar.gz
rust-a2cc1d6b7b499d6b03436db7fc8053aea72f75ac.zip
Merge #11538
11538: feat: Make private editable completions configurable, disable by default r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10253
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/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 <lukastw97@gmail.com>
-rw-r--r--crates/ide_completion/src/config.rs1
-rw-r--r--crates/ide_completion/src/context.rs3
-rw-r--r--crates/ide_completion/src/tests.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs7
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs2
-rw-r--r--docs/user/generated_config.adoc5
-rw-r--r--editors/code/package.json5
7 files changed, 22 insertions, 2 deletions
diff --git a/crates/ide_completion/src/config.rs b/crates/ide_completion/src/config.rs
index 5e5c7efdfb9..c4e91e72830 100644
--- a/crates/ide_completion/src/config.rs
+++ b/crates/ide_completion/src/config.rs
@@ -13,6 +13,7 @@ pub struct CompletionConfig {
     pub enable_postfix_completions: bool,
     pub enable_imports_on_the_fly: bool,
     pub enable_self_on_the_fly: bool,
+    pub enable_private_editable: bool,
     pub add_call_parenthesis: bool,
     pub add_call_argument_snippets: bool,
     pub snippet_cap: Option<SnippetCap>,
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index e986c28b146..c4e145ffcb5 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -360,6 +360,9 @@ impl<'a> CompletionContext<'a> {
             None => return Visible::No,
         };
         if !vis.is_visible_from(self.db, module.into()) {
+            if !self.config.enable_private_editable {
+                return Visible::No;
+            }
             // If the definition location is editable, also show private items
             let root_file = defining_crate.root_file(self.db);
             let source_root_id = self.db.file_source_root(root_file);
diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs
index f063a9638ca..45c7c58dc03 100644
--- a/crates/ide_completion/src/tests.rs
+++ b/crates/ide_completion/src/tests.rs
@@ -64,6 +64,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
     enable_postfix_completions: true,
     enable_imports_on_the_fly: true,
     enable_self_on_the_fly: true,
+    enable_private_editable: 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 76b72707974..af779ee000d 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -161,13 +161,15 @@ config_data! {
             }
         }"#,
         /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
-        completion_postfix_enable: bool          = "true",
+        completion_postfix_enable: bool         = "true",
         /// 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",
+        completion_autoself_enable: bool        = "true",
+        /// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
+        completion_privateEditable_enable: bool = "false",
 
         /// Whether to show native rust-analyzer diagnostics.
         diagnostics_enable: bool                = "true",
@@ -875,6 +877,7 @@ impl Config {
             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,
+            enable_private_editable: self.data.completion_privateEditable_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 c745af3da69..a910a910bb2 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -134,6 +134,7 @@ fn integrated_completion_benchmark() {
             enable_postfix_completions: true,
             enable_imports_on_the_fly: true,
             enable_self_on_the_fly: true,
+            enable_private_editable: true,
             add_call_parenthesis: true,
             add_call_argument_snippets: true,
             snippet_cap: SnippetCap::new(true),
@@ -171,6 +172,7 @@ fn integrated_completion_benchmark() {
             enable_postfix_completions: true,
             enable_imports_on_the_fly: true,
             enable_self_on_the_fly: true,
+            enable_private_editable: true,
             add_call_parenthesis: true,
             add_call_argument_snippets: true,
             snippet_cap: SnippetCap::new(true),
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index b10b0d35522..7e6c8225b18 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -213,6 +213,11 @@ Note that your client must specify the `additionalTextEdits` LSP client capabili
 Toggles the additional completions that automatically show method calls and field accesses
 with `self` prefixed to them when inside a method.
 --
+[[rust-analyzer.completion.privateEditable.enable]]rust-analyzer.completion.privateEditable.enable (default: `false`)::
++
+--
+Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
+--
 [[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
 +
 --
diff --git a/editors/code/package.json b/editors/code/package.json
index 5b75b895d03..1252752a9ae 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -643,6 +643,11 @@
                     "default": true,
                     "type": "boolean"
                 },
+                "rust-analyzer.completion.privateEditable.enable": {
+                    "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.",
+                    "default": false,
+                    "type": "boolean"
+                },
                 "rust-analyzer.diagnostics.enable": {
                     "markdownDescription": "Whether to show native rust-analyzer diagnostics.",
                     "default": true,