]> git.lizzy.rs Git - rust.git/commitdiff
feat: Make private editable completions configurable, disable by default
authorLukas Wirth <lukastw97@gmail.com>
Wed, 23 Feb 2022 15:02:54 +0000 (16:02 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Fri, 25 Feb 2022 21:16:40 +0000 (22:16 +0100)
crates/ide_completion/src/config.rs
crates/ide_completion/src/context.rs
crates/ide_completion/src/tests.rs
crates/rust-analyzer/src/config.rs
crates/rust-analyzer/src/integrated_benchmarks.rs
docs/user/generated_config.adoc
editors/code/package.json

index 5e5c7efdfb924885df26b5e6d5a0bbee74100d84..c4e91e72830bcd962efe8d55936d0066ec9a5195 100644 (file)
@@ -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>,
index e986c28b1466e55785b7f8d9287ed150de301243..c4e145ffcb55a114f9a8be8f21cf90edb4370b4e 100644 (file)
@@ -360,6 +360,9 @@ fn is_visible_impl(
             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);
index f063a9638ca2656aebb88e6b1a468afafcf56e6c..45c7c58dc03aad21e68fa50c370a20ba0a108b34 100644 (file)
@@ -64,6 +64,7 @@ union Union { field: i32 }
     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),
index 76b72707974cf1795bfd6c51e19f7fecd32e57f3..af779ee000d8c3157e46262d992ae440951ce8b5 100644 (file)
@@ -161,13 +161,15 @@ struct ConfigData {
             }
         }"#,
         /// 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 @@ pub fn completion(&self) -> CompletionConfig {
             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(),
index c745af3da69342bf3ea77bd07f9c6284113c0432..a910a910bb24748fe3ecc1b359bbe4418cf95978 100644 (file)
@@ -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),
index b10b0d355222d4307a541539af468c2c359be3bd..7e6c8225b1847796d722faf9d4946e1908b7a004 100644 (file)
@@ -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`)::
 +
 --
index 5b75b895d03e9feeb87ebc41776394e027aac665..1252752a9ae0192bd5e27774194995bb882f2cf2 100644 (file)
                     "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,